You are on page 1of 2

Program:

Take a class „first‟ in which there is a method in public section namely show(). This method
prints the message “I am show method of class first”.

Take another class „second‟ which publicly inherits class first. The class second also contains
a method namely show which prints the message “I am show method of class second”.

Write a program to call both the methods.


#include<iostream.h>
#include<conio.h>

class first
{

public:
void show()
{
cout<<"I am show method of class first";
}

};

class second:public first //class first inherited in class second


{

public:
void show()
{
cout<<"\nI am show method of class second";
}

};

void main()
{

clrscr();

second obj;
obj.first::show(); //show() of class first being called
obj.second::show(); //show() of class second being called

getch();

You might also like