Program to implement the concept of “Behaviour of constructor and destructor under inheritance”.

#include
#include
class first
{
public:
first()
{
cout<<"nBIRTH OF OBJECT OF CLASS FIRST" ;
}
~first()
{
cout<<"nDEATH OF OBJECT OF CLASS FIRST" ;
}
};
class second : public first
{
public:
second()
{
cout<<"n BIRTH OF OBJECT OF CLASS SECOND" ;
}
~second()
{
cout<<"n DEATH OF OBJECT OF CLASS SECOND";
}
};
class third : public second
{
public:
third()
{
cout<<"n BIRTH OF OBJECT OF CLASS THIRD" ;
}
~third()
{
cout<<"n DEATH OF OBJECT OF CLASS THIRD" ;
}
};
class forth : public third
{
public:
forth()
{
cout<<"n BIRTH OF OBJECT OF CLASS FOURTH" ;
}
~forth()
{
cout<<"n DEATH OF OBJECT OF CLASS FOURTH" ;
}
};
main()
{
class forth obj;
getch();
}

Leave a reply