write a program to demonstrate,how constructor and
deconstructor work under multilevel inheritance

Answers were Sorted based on User's Feedback



write a program to demonstrate,how constructor and deconstructor work under multilevel inheritance ..

Answer / kunalsahu

#include<iostream.h>
#include<conio.h>

class a
{
//Data
public:
a()
{
cout<<"class A Constructor\n" ;
}
~a()
{
cout<<"class A Destructor"<<endl;
}
};
class b:public a
{
//Data
public:
b()
{
cout<<"class B Constructor"<<endl;
}
~b()
{
cout<<"class B Destructor"<<endl;
}

};
class c:public b
{
//Data
public:
c()
{
cout<<"class C Constructor"<<endl;
}
~c()
{
cout<<"class C Destructor"<<endl;
}
};
int main()
{ clrscr();
//c *pCObj;
//pCObj=new c();
c k;
getch();
return 0;
}


/*O/p:
class A Constructor
class B Constructor
class C Constructor
class C Destructor
class B Destructor
class A Destructor */

Is This Answer Correct ?    7 Yes 0 No

write a program to demonstrate,how constructor and deconstructor work under multilevel inheritance ..

Answer / nishi

Program is correct, only addition required is to call
destructor you need to call delete(pCObj) explicitly as you
have allocated memory dynamically.

Is This Answer Correct ?    8 Yes 5 No

write a program to demonstrate,how constructor and deconstructor work under multilevel inheritance ..

Answer / archana

class a
{
//Data
public:
a(){cout<<"class A Constructor"<<endl}
~a(){cout<<"class A Destructor"<<endl}
};
class b:public a
{
//Data
public:
b(){cout<<"class B Constructor"<<endl}
~b(){cout<<"class B Destructor"<<endl}
};
class c:public b
{
//Data
public:
c(){cout<<"class C Constructor"<<endl}
~c(){cout<<"class C Destructor"<<endl}
};
int main()
{
c *pCObj;
pCObj = new c();
return 0;
}

O/p:
class A Constructor
class B Constructor
class C Constructor
class C Destructor
class B Destructor
class A Destructor

Is This Answer Correct ?    8 Yes 9 No

Post New Answer

More STL Interview Questions

give me the defination of inheritance?

5 Answers   Infosys,


Assume I have a linked list contains all of the alphabets from "A" to "Z?" I want to find the letter "Q" in the list, how does you perform the search to find the "Q?"

2 Answers  


How the STL's are implemented, What the difference between templates and STL?

1 Answers   Symphony,


what's the difference between abstract class and concreate class? what's the meaning of standard template library(STL)?

2 Answers  


What do you mean by stl?

1 Answers  






how to use C++?

0 Answers   NIIT,


What is stl stack?

0 Answers  


help me i need a c++ program which takes sequesnce of characters and outputed sequence of their token taypes, work same compiler in lexical analysis phase

0 Answers  


What is the stl, standard template library?

0 Answers  


sir please send me bpcl previous question papers

0 Answers   BPCL Bharat Petroleum,


Who created stl?

0 Answers  


Which data structure gives efficient search? A. B-tree B. binary tree C. array D. linked list

21 Answers   ABC, Sun Microsystems,


Categories