Polymorphism refers to the ability of an object to behave differently for the same trigger.
Static polymorphism (Compile-time Polymorphism)
- Static Polymorphism decides which method to execute during compile
time.
- Method Overloading is an example of static polymorphism, and it is
requred to happens static polymorphism.
- Static Polymorphism achieved through static binding.
- Static Polymorphism happens in the same class.
- Object assignment is not required for static polymorphism.
- Inheritance not involved for static polymorphism.
Dynamic Polymorphism (Runtime Polymorphism)
- Dynamic Polymorphism decides which method to execute in runtime.
- Method Overriding is an example of dynamic polymorphism, and it is
requred to happens dynamic polymorphism.
- Dynamic Polymorphism achieved through dynamic binding.
- Dynamic Polymorphism happens between different classes.
- It is required where a subclass object is assigned to super class
object for dynamic polymorphism.
- Inheritance involved for dynamic polymorphism.