Posts

Showing posts from January, 2020

Polymorphism

                        Polymorphism The word  polymorphism  means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance. C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. Consider the following example where a base class has been derived by other two classes − Live Demo #include <iostream> using namespace std ; class Shape { protected : int width , height ; public : Shape ( int a = 0 , int b = 0 ){ width = a ; height = b ; } int area () { cout << "Parent class area :" << endl ; return 0 ; } }; class Rectangle : public Shape { public : Rectangle ( int a = 0 , int b = 0 ): Shape ( a , b ) { } int area () {