write a sample program for pure virtual function in C++



The code for this program is as follows:

#include<iostream.h>
#include<conio.h>
class Base
{

public:
virtual void display() = 0;
};

// This class ingerits from Base and implements display()
class Derived: public Base
{

public:
void display()
{
cout << "eitworld";
}
};

void main()
{
clrscr();
Derived d;
d.display();
getch();
}

In the above program we have declared a pure virtual function in class Base called display() and it is re-defined in the child class Derived. When program execution always start from main() method.
In main() we have called display() method by using the object of the derived class as follows:
Derived d; // object of Derived class
d.display(); // call the method using object
The output of this program is as follows:

Output

eitworld