Virtual Function In C++

Virtual Function In C++

Virtual Function In C++





Virtual Function In C++


#include<iostream.h>
#include<conio.h>
class Base
{
public:
virtual void Display()
{
cout<<"This is the base class virtual function"<<endl;
}
};
class Derived1:public Base
{
public:
void Display()
{
cout<<"This is the Derived1 class display function"<<endl;
}
};
class Derived2:public Base
{
public:
void Display()
{
cout<<"This is the Derived2 class display function"<<endl;
}
};
void main()
{
clrscr();
Base*b;
b=new Base;
b->Display();
b=new Derived1;
b->Display();
b=new Derived2;
b->Display();
getch();

}

Virtual Function In C++

Post a Comment

0 Comments