Polymorphism examples
Polymorphism is an object-oriented programming concept that refers to the ability of a variable, function or object to take on multiple forms. In a programming language exhibiting polymorphism, class objects belonging to the same hierarchical tree (inherited from a common parent class) may have functions with the same name, but with different behaviors. Example The classic example is of the Shape class and all the classes that are inherited from it, such as: Rectangle Triangle Circle This Code is written in C++ class Shape { public : Shape (){} // defining a virtual function called Draw for shape class virtual void Draw (){ cout << " Drawing a Shape " << endl; } }; class Rectangle : public Shape { public : Rectangle (){} // Draw function defined for Rectangle class virtual void Draw (){ cout << " Drawing a Rectangle " << endl; } }; class Triangle : public Shape { public : Triangle ...