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 |
What is stl language?
what is strcture i++ i ++i answer to this i=5 what is the out put
What is a list in c++ stl?
what is an algorithm in terms of STL?
write a program that input four digit number and find how many 7 that number contains
i wanted to know about questions about c,c++ , which is required for placements.... im a fresher
What is a standard template library (stl)?
5. Write c++ function that would intake a string and return the number of occurrences of a given character in that sring Ex:- if the word is “Colombo” and count the occurrences of the letter “o” the function would return 3
draw a flowchart that accepts two numbers and checks if the first is divisible by the second.
wap in c++ which accept a integer array and its size as argument and replaces element having even values with its half and element having odd values with twice its value
method overloading means what?
give me the defination of inheritance?