For following classes class A class B public A class C

For following classes:

class A{

};

class B : public A{

};

class C{

private:

B b1;

};

For the following code in driver.cpp

C c1;

What is the correct order of the body of default constructor been invoked?

A.

A -> B -> C

B.

C->B->A

C.

A->C->B

D.

NONE of above

Solution

Ans) A (A-->B-->C)

Reason:

If we trying to create the object for the subclass then first it checks whether it is having any super class before classing the present class constructor .If it is having then, its super class default constructor will get executed.If that super class has another super class then first that super class default constructor will get executed followed by the execution of sub class constructor.later its sub class constructor like that the order of execution of default constructor will happen in the concept of Inheritance.

For following classes: class A{ … }; class B : public A{ … }; class C{ private: B b1; }; For the following code in driver.cpp C c1; What is the correct order of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site