1.

If class C inherits class B. And B has inherited class A. Then while creating the object of class C, what will be the sequence of constructors getting called?(a) Constructor of C then B, finally of A(b) Constructor of A then C, finally of B(c) Constructor of C then A, finally B(d) Constructor of A then B, finally CThe question was asked at a job interview.My question comes from Constructors topic in section Constructors and Destructors of Object Oriented Programming

Answer»

The correct answer is (d) CONSTRUCTOR of A then B, finally C

The explanation is: While creating the OBJECT of CLASS C, its constructor would be CALLED by DEFAULT. But, if the class is inheriting some other class, firstly the parent class constructor will be called so that all the data is initialized that is being inherited.



Discussion

No Comment Found

Related InterviewSolutions