Page 189 - DCAP404 _Object Oriented Programming
P. 189
Object-oriented Programming
Notes
Did u know? What is Polymorphic functions?
Polymorphic functions are functions that can be applied to objects of more than one type.
//Program to show the hierarchical inheritance
# include < iostream.h>
# include < conio.h>
class father //Base class declaration
{
int age;
char name [15];
public:
void get ( )
{
cout << “father name please”; cin >> name;
cout << “father’s age please”; cin >> age;
}
void show ( )
{
cout << “In father’s name is : “<<name;
cout << “In father’s age is: “<< age;
}
};
class son : public father //derived class 1
{
char name [20];
int age;
public;
void get ( );
void show ( );
};
void son :: get ( )
{
father :: get ( );
cout << “your (son) name please” <<“in”; cin >>name;
cout << “your age please” <<“In”; cin>>age;
}
void son :: show ( )
{
father : : show ( );
cout << “In my name is : “<<name;
cout << “In my age is : “<< age;
182 LOVELY PROFESSIONAL UNIVERSITY