Machine-translated by Google. Questions are authored in English.
Top

Constructors and Destructors Questions and Answers

11.

Assume that we have constructor function for both Base and Derived classes. Now consider the declaration :
main ( )
Base *p = new Derived;
In what sequence, the constructor will be executed ?

Exam Year(s)

UGC NET - 2013,

Answer: B

With Base *p = new Derived;, the Base class constructor runs first and then the Derived class constructor. A derived object contains a base part, and the base part has to be built before the derived part can use it.

The destructors run in the opposite order. The options saying that Derived runs first, or that one constructor is never called, are wrong, because creating the object with new Derived calls both constructors.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Constructors and Destructors Questions and Answers || Constructors and Destructors MCQ Questions and Answers || Constructors and Destructors GK Questions and Answers || Constructors and Destructors GK MCQ Questions || Constructors and Destructors Multiple Choice Questions and Answers || Constructors and Destructors GK || GK on Constructors and Destructors || Object Oriented Programming Questions and Answers || Object Oriented Programming MCQ Questions and Answers || Object Oriented Programming GK Questions and Answers || GK on Object Oriented Programming