Constructors And Destructors(C++ Programming ) Questions and Answers

Question 1.

Which of the following statement is correct whenever an object goes out of scope?


  1.    The default constructor of the object is called.
  2.    The parameterized destructor is called.
  3.    The default destructor of the object is called.
  4.    None of the above.
Explanation:-
Answer: Option C. -> The default destructor of the object is called.



Question 2.

Which of the following statement is correct about constructors?


  1.    A constructor has a return type.
  2.    A constructor cannot contain a function call.
  3.    A constructor has no return type.
  4.    A constructor has a void return type.
Explanation:-
Answer: Option C. -> A constructor has no return type.



Question 3.

To ensure that every object in the array receives a destructor call, always delete memory allocated as an array 

with operator __________ .


  1.    destructor
  2.    delete
  3.    delete[]
  4.    kill[]
  5.    free[]
Explanation:-
Answer: Option C. -> delete[]



Question 4.

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


  1.    constructor
  2.    virtual function
  3.    destructor
  4.    main
Explanation:-
Answer: Option A. -> constructor



Question 5.

How many times a constructor is called in the life-time of an object?


  1.    Only once
  2.    Twice
  3.    Thrice
  4.    Depends on the way of creation of object
Explanation:-
Answer: Option A. -> Only once



Question 6.

Which of the following statements are correct?


  1.    Constructor is always called explicitly.
  2.    Constructor is called either implicitly or explicitly, whereas destructor is always called implicitly.
  3.    Destructor is always called explicitly.
  4.    Constructor and destructor functions are not called at all as they are always inline.
Explanation:-
Answer: Option B. -> Constructor is called either implicitly or explicitly, whereas destructor is always called implicitly.



Question 7.

Which of the following never requires any arguments?


  1.    Member function
  2.    Friend function
  3.    Default constructor
  4.    const function
Explanation:-
Answer: Option C. -> Default constructor



Question 8.

Which of the following statement is correct?


  1.    A constructor of a derived class can access any public and protected member of the base class.
  2.    Constructor cannot be inherited but the derived class can call them.
  3.    A constructor of a derived class cannot access any public and protected member of the base class.
  4.    Both A and B
Explanation:-
Answer: Option D. -> Both A and B



Question 9.

A class's __________ is called when an object is destroyed.


  1.    constructor
  2.    destructor
  3.    assignment function
  4.    copy constructor
Explanation:-
Answer: Option B. -> destructor



Question 10.

Destructors __________ for automatic objects if the program terminates with a call to function exit 

or function abort.


  1.    are called
  2.    are inherited
  3.    are not called
  4.    are created
Explanation:-
Answer: Option C. -> are not called