Page 204 - DCAP404 _Object Oriented Programming
P. 204
Unit 9: Inheritance
class derived: public base Notes
{
public:
void display();
void show();
};
void derived::display()
{
cout<<“\nderived class display() function”;
}
void derived::show()
{
cout<<“\nderived class show() function”;
}
void main()
{
clrscr();
base *b;
derived d;
b=&d;
b->display();
b->show();
getch();
}
We can define data member and member function with the same name in both base and derived
class. When the function with same name exists in both class and derived class, the function in
the derived class will get executed. This means, the derived class will get executed. This means,
the derived class function overrides the base class function.
Example:
Class base A
{
LOVELY PROFESSIONAL UNIVERSITY 197