In multilevel inheritance constructors will be executed
from the .... class to ... class




Answers were Sorted based on User's Feedback



In multilevel inheritance constructors will be executed from the .... class to ... class..

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

In multilevel inheritance constructors will be executed from the .... class to ... class..

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

Post New Answer




More OOPS Interview Questions

//what is wrong with the programme?? #include<iostream.h> template <class first> class dd { first i; public: void set(); void print(); }; void dd< first>:: set() { cin>>i; } void dd< first>::print() { cout<<"\n"<<i; } void main() { dd <char>g; g.set(); g.print(); }

1 Answers  


what is new operator in c++

1 Answers  


i have to create a view in SQL as like in ORACLE DATA EXPRESS EDITION

2 Answers   CTS,


Write a program to demonstrate the use of 'Composition' in C++

2 Answers  


what is a class

6 Answers  






A file pointer always contains the __________ of the file

5 Answers  


define oops concept with example

1 Answers   Cap Gemini,


Name an advantage of array over linked list?

24 Answers   IBM, GML, Software Solutions,


Why we are use # in begning of programme of c++.

2 Answers   Syntel,


what is overloading and overriding?

7 Answers  


Differences between inline functions and non-inline functions?

4 Answers   Ness Technologies,


What do you mean by Encapsulation?

0 Answers   Ittiam Systems,






Categories