Documentation
Output
This is Derived class show() function
----------------------------------------------------------------------------------------------------------
✔ Pointer to base class
✔ Pointer to derived class
✔ Virtual function usage
✔ Runtime polymorphism
Key Concept
-
A base class pointer can point to a derived class object
-
If the function is declared virtual, the derived class function is called at runtime
Explanation
-
virtualkeyword ensures dynamic binding -
Function call is resolved at runtime
-
Even though pointer is of Base type, Derived function is executed
-
This concept is called Runtime Polymorphism
- Virtual functions are accessed using base class pointers