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
How to hide the base class functionality in Inheritance?
What is difference between multiple inheritance and multilevel inheritance?
Where You Can Use Interface in your Project
write a code for this. serial_number contained in the header of the file will be read , if this serial number is less than a previous serial number within a successfully processed file, or is the same as another serial number within a successfully processed file, or if the field contains anything other than 7 digits, then the file must error with the reason ‘Invalid SERIAL_NUMBER’.
How do you define a class in oop?
Which is not an object oriented programming language?
write a C++ program for booking using constructor and destructor.
Can enum be null?
what type of questions
What are the 3 pillars of oop?
What is class in oop with example?
What is property in oops?
What is inheritance write a program to show use of inheritance?
What is difference between inheritance and polymorphism?
What is the oops and benefits of oops programming?