- Polymorphism means the ability to take more than one form.
- It allows a single name to be used for more than one related purpose.
- Moreover, It means a the ility of operators and functions to act differently in different situations.
- Different types of polymorphism are:
Compile Time Polymorphism
- Compile time polymorphism is function and operator overloading.
- Function overloading the practice of declaring the same function with different signatures.
- The same function name will use with a different number of parameters and parameters of the different type.
- Overloading of functions with different return type not allowed.
- Operator overloading is the ability to tell the compiler how to perform a certain operation based on its corresponding operator’s data type.
- Also, Like + performs addition of two integer numbers, concatenation of two string variables and works totally different when used with objects of time class.
Dynamic Binding (Late Binding)
- Dynamic binding is the linking of a routine or object at runtime based on the conditions at that moment.
- So, It means that the code associated with a given procedure call not known until the time of the call.
- At run-time, the code matching the object under current reference will call.
- The virtual function is a member function of a class, whose functionality can be overridden in its derived classes.
- Moreover, The whole function body can replace with a new set of implementation in the derived class.
- Also, It declared as virtual in the base class using the virtual keyword.