This is a C++ program that demonstrates the use of abstract classes and virtual functions. The program defines an abstract class Shape with a pure virtual function draw(), which means that any class that derives from Shape must implement the draw() function.
The program also defines two classes Rectangle and Square that inherit from the Shape class and implement the draw() function. In the main() function, we create an object of the Rectangle class and use it to call the draw() function. We then create an object of the Square class and use it to call the draw() function.
#include<iostream> using namespace std; class Shape { public: virtual void draw()=0; //=0 is pure virtual function }; class Rectangle:public Shape { public : void draw() { cout<<"Draw Rectangle"<<endl; } }; class Square:public Shape { public : void draw() { cout<<"Draw Square"<<endl; } }; int main() { Shape *o =new Rectangle(); o->draw(); o =new Square(); o->draw(); return 0; }To download raw file Click Here
Draw RectangleDraw Square
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions