You are on page 1of 2

/******************************************************************************

C++ program to implement Run time polymorphism using virtual functions

*******************************************************************************/

#include <iostream.h>

class A
{
public:
virtual void message()
{
cout<<"message () from A"<<endl;
}
void show()
{
cout<<"show() from A"<<endl;
}
};

class B:public A
{
public:
void message()
{
cout<<"message () from B"<<endl;
}
void show()
{
cout<<"show() from B"<<endl;
}
};
int main()

A *a;

B b;

a=&b;

a->message();//run time polymorphism

a->show();// compile time polymorphism

return 0;

Output

message () from B                                                                                    
                                                
show() from A     

prepared by Kiran

You might also like