Virtual Functions-
- Virtual function is member function of a class.
- Virtual function is declared with the keyword virtual.
- Virtual function takes a different functionality in the derived class.
- It is used to implement run time polymorphism.
For example:-
#include<iostream.h>
#include<conio.h>
Class pixeles
{
public:
virtual void disp()
{
cout<<“PIXELES CLASSES FOR BCA & MCA” ;
}
};
Class india : public pixeles
{
public:
void disp()
{
cout<<“\n A SUCCESS KEY”;
}
};
class success : public pixeles
{
public:
void disp()
{
cout<<“\n www.pixelesindia.com”;
}
};
void main()
{
clrscr();
pixeles op;
india pp;
success sll;
op.disp();
pp.disp();
ll.disp();
pixels *pt;
pt= &pp;
pt->disp();
pt=&sll
pt->disp();
getch();
}
Post Views: 3,813