In multilevel inheritance constructors will be executed
from the .... class to ... class

Answers were Sorted based on User's Feedback



In multilevel inheritance constructors will be executed from the .... class to ... class..

Answer / ps

Constructors are always executed from the parent to child
ie in the example below:
#include <iostream>
using namespace std;

class base1
{
public:
base1()
{
cout<<"In constructor of base1"<<endl;
}
~base1()
{
cout<<"In destructor of base1"<<endl;
}

};

class base2:public base1
{
public:
base2()
{
cout<<"In constructor of base2"<<endl;
}
~base2()
{
cout<<"In destructor of base2"<<endl;
}
};
class derived :public base2
{
public:
derived()
{
cout<<"In constructor of derived"<<endl;
}
~derived()
{
cout<<"In destructor of derived"<<endl;
}
};

void main()
{
base1 b1;
base2 b2;
derived d1;
}

o/p:
In constructor of base1 --- for object b1
In constructor of base1 --- for object b2
In constructor of base2-----
In constructor of base1-for object d1
In constructor of base2
In constructor of derived

Is This Answer Correct ?    19 Yes 6 No

In multilevel inheritance constructors will be executed from the .... class to ... class..

Answer / chaitanya

In constructor of base1-----for object b1
In constructor of base1-----for object b2
In constructor of base2------for object b2
In constructor of base1-----for object d1
In constructor of base2-----for object d1
In constructor of derived----for object d1
In destructor of derived
In destructor of base2
In destructor of base1

Is This Answer Correct ?    12 Yes 6 No

Post New Answer

More OOPS Interview Questions

What is polymorphism and types?

0 Answers  


Name a typical usage of polymorphism

3 Answers  


What are the three parts of a simple empty class?

0 Answers  


Why do we use polymorphism?

0 Answers  


WHEN A COPY CONSTER IS CALL ?

4 Answers  






Finding of the 4 larger (bigger) numbers from the list like{1245,4587,2145,1163,29987,65783.....}

1 Answers   Wipro,


to find out the minimum of two integer number of two different classes using friend function

0 Answers  


• What are the desirable attributes for memory managment?

0 Answers  


what type of question are asked in thoughtworks pair programming round ?

0 Answers   Thought Works,


WRITE A SIMPLE C++ PROGRAM TO SWAP TWO NOS WITHOUT USING TEMP

2 Answers  


Why multiple inheritance is not allowed?

0 Answers  


What is the difference between C++ and java?

6 Answers   Atos Origin,


Categories