#include<iostream.h>
#include<conio.h>
class father
{
protected:
int age;
public:
father(int x)
{
age=x;
}
virtual void iam()
{
cout<<"I AM THE FATHER, my age is "<<age;
}
};
class son:public father
{
public:
son(int s):father(s)
{
age=s;
}
void iam()
{
cout<<"I am son, my age is "<<age;
}
};
class daughter:public father
{
public:
daughter(int d):father(d)
{
age=d;
}
void iam()
{
cout<<"I am daughter, my age is "<<age;
}
};
void main()
{
father f1(45),*ptr;
son s1(20);
daughter d1(18);
clrscr();
cout<<"ptr point the base class father obj\n";
ptr=&f1;
ptr->iam();
cout<<"\n\nptr point the class son obj\n";
ptr=&s1;
ptr->iam();
cout<<"\n\nptr point the class daughter obj\n";
ptr=&d1;
ptr->iam();
getch();
}
#include<conio.h>
class father
{
protected:
int age;
public:
father(int x)
{
age=x;
}
virtual void iam()
{
cout<<"I AM THE FATHER, my age is "<<age;
}
};
class son:public father
{
public:
son(int s):father(s)
{
age=s;
}
void iam()
{
cout<<"I am son, my age is "<<age;
}
};
class daughter:public father
{
public:
daughter(int d):father(d)
{
age=d;
}
void iam()
{
cout<<"I am daughter, my age is "<<age;
}
};
void main()
{
father f1(45),*ptr;
son s1(20);
daughter d1(18);
clrscr();
cout<<"ptr point the base class father obj\n";
ptr=&f1;
ptr->iam();
cout<<"\n\nptr point the class son obj\n";
ptr=&s1;
ptr->iam();
cout<<"\n\nptr point the class daughter obj\n";
ptr=&d1;
ptr->iam();
getch();
}
0 comments:
Post a Comment