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 different between oops and c++

0 Answers   IIT,


what is data abstraction with example.

1 Answers  


What is memory leak and memory corruption?

1 Answers   TCS,


What is function overloading?,describe it with the example.

5 Answers  


c++ provides classes...and classes do what we want but why then strcut are used...if we say data hiding... it is also provided by c++ in structs then why to prefer clasess

1 Answers   HCL, TCS,






What is a null tree?

0 Answers  


What is the difference between inheritance and polymorphism?

0 Answers  


Why is oop better than procedural?

0 Answers  


In OverLoading concept,Why they are not consider return value and why they are consider only parameters in method? For ex: public int Add(int a,int b){...} public String Add(int a,int b){...}

1 Answers  


define a string class. overload the operator == to compare two strings

2 Answers   Birla, Ericsson, HCL, Infosys, Infotech, MCAS, Satyam,


how much classes are used in c++

5 Answers  


what is polymorpsim? what are its types?

8 Answers  


Categories