#include< iostream.h>
#include< conio.h>
class abc
{
protected :
int a,b;
public:
void take()
{
cout<< "\nEnter two 'int' values::";
cin>>a>>b;
}
};
class xyz:public abc
{
public:
void display()
{
cout<< "\nSum for 1st derived class="<< a+b;
}
};
class mn:public abc
{
public:
void display()
{
cout<< "\nSum for 2nd derived class:"<< a+b;
}
};
void main()
{
clrscr();
xyz ob;
mn ob1;
abc *ptr;
ptr=&ob;
cout<< "\nFor object of 1st derived class."<< endl;
ptr->take();
ptr->display();
cout<< "\nFor object of 2nd derived class."<< endl;
ptr=&ob1;
ptr->take();
ptr->display();
getch();
}
No comments:
Post a Comment