Runtime Polymorphism - OOPs Concept in C++
How is Runtime Polymorphism used in OOPs concept of C++?
Runtime Polymorphism is a form of polymorphism at which function binding occurs at runtime.
You can have a parameter in subclass, same as the parameters in its super classes with the same name. Virtual keyword is used in superclass to call the subclass. The function call takes place on the run time, not on the compile time.
virtual void area()
cout << "Base class area Calculation"
Class Square : public Shape
cout << "Derived class area Calculation"
Derived class area Calculation
In the above example, square is the super class and shape is the sub class of area. Here virtual keyword indicates the member function of the shape super class. If you call member function, binding occurs on run time only.