Search This Blog

Tuesday, 13 November 2012

Constructors, Destructors in inheritance

#include<iostream.h>
#include<conio.h>
class student
{
int rlno;
public:
student()
{
cout<<"Base Constructor\n";
}
void getData()
}
cout<<"Get Roll Number";
cin>>rlno;
}
void putData()
{
cout<<"Roll Number="<<rlno<<"\n";
}
~student()
{
cout<<"Base Destructor\n";
}
};
class mark:public student
{
int m;
public:
mark()
{
cout<<"Derived constructor\n";
}
void getData()
{
cout<<"Get Mark";
cin>>m;
}
void putMark()
{
cout<<"Mark="<<m<<"\n";
}
~mark()
{
cout<<"Derived Destructor\n";
}
};
void main()
{
clrscr()
mark M;
getch();
}

Output:
Base Constructor
Derived Constructor
Derived Destructor
Base Destructor


No comments:

Post a Comment