Write a program to perform the concept of virtual function in C++?



#include<iostream.h>
#include<conio.h>
class a
{
public:
virtual void show()
{
cout<<"\nThis is class A";
}
};
class b:public a
{
public:
void show()
{
cout<<"\nThis is class B";
}
};
void main()
{
clrscr();
class a *p;
class a obj;
class b obj1;
p=&obj;
p->show();
p=&obj1;
p->show();
getch();
}



OUTPUT:-

This is class A
This is class B
 

Comments

Popular posts from this blog

Write a program to add two number using inline function in C++?

Traversing of elements program with algorithm and Flowchart