//Program to show how virtual function works

| |


#include<iostream.h>
#include<conio.h>
                class base
                {
                public:
                virtual void display()
                {
                cout<<"base class display is called \n";
                }
                };
                class derv1:public base
                {
                public:
                void display()
                {
                cout<<"derv1's display called \n";
                }
                };
                class derv2:public base
                {
                public:
                void display()
                {
                cout<<"derv2's display called\n";
                }
                };
                int main()
                {
                clrscr();
                base*ptr;
                derv1 d1;
                derv2 d2;
                ptr=&d1;
                ptr->display();
                ptr=&d2;
                ptr->display();
                getch();
                return 0;
   }
<