Monday, 24 June 2013

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
 

No comments:

Post a Comment