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

Write pseudo code for push in a stack?

2 Answers   emc2,


There are 2 empty jars of 5 and 3 liters capacity. And a river is flowing besides. I want to measure 4 liters of wanter using these 2 jars. How do you do this?

4 Answers  


Difference between new operator and operator new

2 Answers  


what is the use of template classes in c++

1 Answers  


What does no cap mean?

0 Answers  






difference between abstraction and encapsulation with progarammatic eg. hi,just recently i went for an interview .The interviewer asked what is the difference between abstraction and encapsulation with programmatic eg. I gave the answer as encapsulation mean hiding the relevant data which is not useful for the user, eg a electric fan .hiding the information how the electricity is converted into machanical energy. abtraction showing only the relevant data to the user eg electric fan. it look ,its color ,it design etc only relevant data. Then the interviewer asked me, give me some programmic eg .I Said Let assume a web form having control like textbox,button etc. The user can view textbox,button etc this is the eg of abstraction and when the user click on the button how he is redirected is not known by the user is the eg of the encapsulation. Am I Correct .was the answer given by me is perfect .now i am planing to go for an another interview should i give the same answer.IF not please suggest me a better answer.with some good eg Please help

1 Answers  


what do you mean by static member variable?

2 Answers  


What is late bound function call and early bound function call? Differentiate.

2 Answers   Ness Technologies,


What is data binding?

4 Answers   Ittiam Systems,


What are the two different types of polymorphism?

0 Answers  


what is the drawback of classical methods in oops?

0 Answers  


Describe what an Interface is and how it?s different from a Class.

7 Answers   Spinsys,


Categories