A program to demonstrate the concept of runtime polymorphism in C++

#include<iostream>
#include<conio.h>
using namespace std;
class Base
{
public:
virtual void show()
{
cout<<“Base class”;
}
};
class Derive: public Base
{
public:
void show()
{
cout<<“Derived class”;
}
};
main()
{
Base *b;
Base a;
Derive d;
b=&a;
b->show();
cout<<endl;
b=&d;
b->show();
getch();
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *