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
Can we create object of abstract class?
How to call a non virtual function in the derived class by using base class pointer
Which is better struts or spring?
any one please tell me the purpose of operator overloading
What are the benefits of interface?
Advantage and disadvantage of routing in telecom sector
What is this pointer in oop?
What is encapsulation example?
What is the important feature of inheritance?
write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.
What are benefits of oop?
What is an interface in oop?
what is different between oops and c++
What is polymorphism what is it for and how is it used?
What is polymorphism in oop example?