write a program to demonstrate,how constructor and
deconstructor work under multilevel inheritance
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister
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?"
c# support late binding or early binding.
WHAT IS FIBONACCI SERIES?
What two types of containers does the stl provide?
write a program to convert a decimal number in to its equivalent binary number?
How Find, Replace and Go To commands ca be used to substitute one character string for another? Explain with the heIp of an example.
What does stl mean in slang?
Describe the elements of Microsoft Word screen. Write down steps for creating, saving, retrieving, editing and printing a document.
what is electronic software
Write a program to print the swapping in two no and using three variable.
Distinguish between: a) Normal layout & Print Layout views b) Windows Clipboard & office Clipboard c) Save & Save As Commands d) Program File & Data File e) Pie Charts & Barr Charts