- Polymorphism means multiple forms that means having more than one function with the same name but with different functionalities.
- In C++ program there are 2 types of polymorphism, they are:
- Compile-time polymorphism
- Run-time polymorphism
Compile-time polymorphism
- At compile time which is implemented known as Compile-time polymorphism. It is otherwise known as static polymorphism.
- Method overloading is also an example for compile-time polymorphism.
- Method overloading which allows you to have more than one function with the same function name but with different functionality.
Sample Code
Output
Run-time polymorphism
- Run-time polymorphism is otherwise known as dynamic polymorphism.
- Function overriding is an example of runtime polymorphism that means when the child class contains the method which is already present in the parent class.
- In function overriding, parent and child class both contains the same function with the different definition.
- The call to the function is determined at runtime is known as runtime polymorphism.