Introduction
- Poly means many and Morph means form.
- A method can behave differently in different situations.
- Examples:
- Person can be a father, husband, employee, etc
- Water can be liquid, solid or gas.
Types of Polymorphism -
- Compile Time / Static Polymorphism / Method Overloading
- Run Time / Dynamic Polymorphism / Method Overriding
Method Overloading: Multiple methods in the same class with the same name but different parameters. On the basis of RETURN TYPE overloading CAN’T be done.
Method Overriding: A method in a subclass has the same name, return type, and parameters as a method in the parent class.