1.

If a derived class object is created, which constructor is called first?(a) Base class constructor(b) Derived class constructor(c) Depends on how we call the object(d) Not possibleI had been asked this question in a job interview.This interesting question is from Inheritance topic in chapter Inheritance & its Types of Object Oriented Programming

Answer»

The correct choice is (a) BASE class constructor

Best explanation: First the base class constructor is INVOKED. When we create a derived class OBJECT, the system tries to invoke its constructor but the class is derived so first the base class must be INITIALIZED, HENCE in turn the base class constructor is invoked before the derived class constructor.



Discussion

No Comment Found

Related InterviewSolutions