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

how to overload << and >> operator in c++

3 Answers   Wipro,


what is c++

2 Answers  


What do stl stand for?

0 Answers  


how to swap two numbers in a linked list without exchanging the data but only the links?

3 Answers   Wipro,


What is stl in c++ with example?

0 Answers  






what is template and type convertion

0 Answers   TATA,


a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.

0 Answers  


How Find, Replace and Go To commands ca be used to substitute one character string for another? Explain with the heIp of an example.

1 Answers  


Write a program in C++ to concatenate two strings into third string using pointers

5 Answers  


Is there any error below, its a code to delete all entires from a map #include <map> #include iostream.h int main() { int i =0; map <int, char> TestMap; while(i<3) { TesMap.insert(TestMap::value_type(i,Test)); i++; } typedef map<int, char> :: iterator mapIter =TestMap.begin(); if(mapIter!=TestMap.end()) { TestMap.erase(mapItrer); ++mapIter; } return 0; }

0 Answers  


Explain how to insert a hyperlink in to an Excel worksheet and save a Word document as a Web page.

1 Answers  


Diffrernce Between Overloading and Overriding?

2 Answers   Wipro,


Categories