//multi level inheritance
#include <iostream.h>
#include <conio.h>
class A
{
protected:
int a;
public:
A()
{
cout<<"constructor A executed"<<endl;
}
void input()
{
cout<<"enter a ";
cin>>a;
}
void output()
{
cout<<a<<endl;
}
};
class B:public A
{
public:
B()
{
cout<<"constructor B executed"<<endl;
}
};
class C:public B
{
public:
C()
{
cout<<"constructor C executed"<<endl;
}
};
void main()
{
C obj;
obj.input();
obj.output();
getch();
}
#include <iostream.h>
#include <conio.h>
class A
{
protected:
int a;
public:
A()
{
cout<<"constructor A executed"<<endl;
}
void input()
{
cout<<"enter a ";
cin>>a;
}
void output()
{
cout<<a<<endl;
}
};
class B:public A
{
public:
B()
{
cout<<"constructor B executed"<<endl;
}
};
class C:public B
{
public:
C()
{
cout<<"constructor C executed"<<endl;
}
};
void main()
{
C obj;
obj.input();
obj.output();
getch();
}
0 comments:
Post a Comment