/*
Run time Polymorphism
*/
#include<iostream>
using namespace std;
class Base
{
public:
void display()
{
cout<<"\n\n Display of Base. ";
}
virtual void show()
{
cout<<"\n\n Show of Base. ";
}
};
class Derived : public Base
{
public:
void display()
{
cout<<"\n\n Display of Derived. ";
}
void show()
{
cout<<"\n\n Show of Derived. ";
}
};
int main()
{
Base B;
Derived D;
Base *bptr;
bptr=&B;
cout<<"\n\n Pointer contain Base Class: ";
bptr->display();
bptr->show();
bptr=&D;
cout<<"\n\n Pointer contain Derived Class: ";
bptr->display();
bptr->show();
return 0;
}
Run time Polymorphism
*/
#include<iostream>
using namespace std;
class Base
{
public:
void display()
{
cout<<"\n\n Display of Base. ";
}
virtual void show()
{
cout<<"\n\n Show of Base. ";
}
};
class Derived : public Base
{
public:
void display()
{
cout<<"\n\n Display of Derived. ";
}
void show()
{
cout<<"\n\n Show of Derived. ";
}
};
int main()
{
Base B;
Derived D;
Base *bptr;
bptr=&B;
cout<<"\n\n Pointer contain Base Class: ";
bptr->display();
bptr->show();
bptr=&D;
cout<<"\n\n Pointer contain Derived Class: ";
bptr->display();
bptr->show();
return 0;
}