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

Q1. A. What is unary operator? List out the different operators involved in the unary operator. B. What is an adjust field format flag? Q2. A. Distinguish between a # include and #define. B. Can a list of string be stored within a two dimensional array? Q3. A.Explain how a pointer to function can be declared in C++? B.List the merits and demerits of declaring a nested class in C++? Q4. A. What are the syntactic rules to be avoid ambiguity in multiple inheritence? B. Explain the operation of overloading of an assignment operator. Q5. A. Explain how the virtual base class is different from the conventional base classes of the opps. B. Explain how an exception handler is defined and invoked in a Program. Q6. A. What is a binary file? List the merits and demerits of the binary file usagein C++. B. Write short notes on Text Manipulation Routines. C. Write bites in Turbo c++ Header (“Include”) Files.

0 Answers   GE, Infosys, Microsoft, NIM,


I am doing my BS.c MATHS CAN I ABLE TO JOIN IN NIIT?

2 Answers  


tell about sorted linked list

1 Answers  


What is the stl, standard template library?

0 Answers  


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

1 Answers  






How is stl different from c++ standard library?

0 Answers  


Name the different types of stl containers.

0 Answers  


What is meant by stl in c++?

0 Answers  


What is a standard template library (stl)? What are the various types of stl containers?

0 Answers  


Describe the elements of Microsoft Word screen. Write down steps for creating, saving, retrieving, editing and printing a document.

2 Answers  


What is the disadvantage of templates ?

2 Answers   NSN, Symphony,


write a program to search and display the position of an element in a single-dimentional array using function.

1 Answers  


Categories