You are on page 1of 2

//Program to demonstrate virtual function. #include<iostream.h> #include<conio.

h> class base { Public: virtual void print() { cout<<\n I am the base class; } void show() { cout<<\n I am the show base; } }; class derived:public base { public: void print() { cout<<\n I am the derived class; } void show() { cout<<\n I am the show derived; } }; void main() { clrscr(); base *pbase; base obase; derived oder; pbase=&base; base->print(); pbase->show(); pbase->&oder; pbase->print(); pbase->show(); getch(); }

OUTPUT: I am the base class I am the show base I am the derived class I am the show base

You might also like