Tuesday, October 14, 2008

7.3 PROGRAM TO IMPLEMENT SINGLE INHERITENCE

#include
#include
class sum
{
int a,b;
public:
void read(int x,int y)
{
a=x;
b=y;
}
void display()
{
cout<<"sum"< }
};
class ABC:public sum
{
int x,y,z;
public:
void read(int a,int b,int c)
{
x=a;y=b; z=c;
}
void display()
{
cout<<"sum="< }
};
void main()
{
sum *p,o1;
ABC o2,*p1;
clrscr();
p=&o1;
p->read(20,30);
p->display();
p1=&o2;
p1->read(20,30,40);
p1->display();
getch();
}

Output: sum50sum=90

No comments: