Thursday, December 13, 2012

write a program of virtual function in c++


#include<iostream.h>
#include<conio.h>
class Base
{
public:
virtual void display()
{
cout<<"This is base class display function\n";
}
};
class Derived:  public Base
{
public:
void display()
{
cout<<"This is Derived class display function\n";
}
};
void main()
{
clrscr();
Base *ptr;
Derived obj;
ptr=&obj;
ptr->display();
getch();
}

Output