Quiz: Constructor And Destructor

To View Tricks: Login Required

Number of Questions: 20

Question: 1 -

Like constructors, can there be more than one destructors in a class?

Options:
  1. Can't Say

  2. No

  3. May Be

  4. Yes

  5. Answer:

    No

    Solution:

    There can be only one destructor in a class. Destructor's signature is always ~ClassNam()and they can not be passed arguments.


Question: 2 -

State whether the following statements about the constructor are True or False. i) constructors should be declared in the private section. ii) constructors are invoked automatically when the objects are created.

Options:
  1. True,False

  2. False,True

  3. False,False

  4. True,True

  5. Answer:

    False,True

    Solution:

    Statement 1 is false and statement 2 is true.


Question: 3 -

Destructor has a same name as the constructor and it is preceded by?

Options:
  1. ~

  2. $

  3. ?

  4. !

  5. Answer:

    ~

    Solution:

    Destructor has a same name as the constructor and it is preceded by ~.


Question: 4 -

Which of the following gets called when an object is being created?

Options:
  1. Virtual Function

  2. Destructors

  3. Main

  4. Constuctor

  5. Answer:

    Constuctor

    Solution:

    Virtual Function gets called when an object is being created.


Question: 5 -

Which of the followings is/are automatically added to every class, if we do not write our own.

Options:
  1. Assignment Operator

  2. All of the above

  3. Copy Constructor

  4. A constructor without any parameter

  5. Answer:

    All of the above

    Solution:

    In C++, if we do not write our own, then compiler automatically creates a default constructor, a copy constructor and a assignment operator for every class.