In multilevel inheritance constructors will be executed
from the .... class to ... class
Answers were Sorted based on User's Feedback
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 |
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 |
what is virtual function in c++
how can we design a magic square in c++?or suggest me the basic idea of it.
Write a program to reverse a string using recursive function?
What is the difference between C++ and java?
How to execute business logic for only once ..?even though user clicks submit button multiple times by mistake..? (i disabled JavaScript)
WHAT'S THE OOPS BASIC OOPS CONCEPTS IN DOTNET
Why is there no multiple inheritance?
What is the purpose of enum?
What is encapsulation process?
should we use linear search or binary search if elements are placed in random order or mixed?in both cases? i need a little bit detail ans?thnks
What is the difference between class and structure?
What do we mean by a hidden argument in a function?