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


Please Help Members By Posting Answers For Below Questions

Can an interface inherit a class?

545


Whats is abstraction in oops?

577


What is balance factor?

570


What are properties in oop?

586


What is property in oops?

549






What is interface in oop?

639


How long to learn object oriented programming?

549


What is the highest level of cohesion?

560


What type of loop is a for loop?

671


What is a class in oop?

586


How do you achieve polymorphism?

598


what is the sylabus for priliminaries?

1665


What is static in oop?

579


What is the difference between static polymorphism and dynamic polymorphism?

562


What does and I oop mean in text?

605