In multilevel inheritance constructors will be executed
from the .... class to ... class
Answer Posted / 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 |
Post New Answer View All Answers
What are benefits of oop?
Why do we use inheritance?
What do you mean by abstraction?
What is overloading in oops?
What are the 3 principles of oop?
What is the real time example of encapsulation?
What is a null tree?
Get me an image implementation program.
What are the data types in oop?
What is the highest level of cohesion?
write a programe to calculate the simple intrest and compund intrest using by function overlading
What is property in oops?
What is static modifier?
How does polymorphism work?
Why is abstraction used?