PROGRAM USING VIRTUAL FUNCTIONS

by - December 20, 2018

/*WRITE A PROGRAM USING VIRTUAL FUNCTIONS*/

#include<iostream.h>
#include<conio.h>
class base
{
public:
void display()
{
cout<<"\nDisplay base";
}
virtual void show()
{
cout<<"\nShow base";
}
};
class derived:public base
{
public:
void display()
{
cout<<"\nDisplay derived";
}
void show()
{
cout<<"\nShow derived";
}
};
void main()
{
base b;

derived d;
base*bptr;
cout<<"\nbptr points to base";
bptr=&b;
bptr->display();
bptr->show();
cout<<"\nbptr points to derived";
bptr=&d;
bptr->display();
bptr->show();
return0;
}

----------------------------------------------------------
OUTPUT:-

You May Also Like

0 comments