Polymorphism in Java OOP
Polymorphism is word made from two words "Poly" which means many and "morph" means shape/form. Polymorphism means "ability to take multiple shapes or forms". In Java, method and Object both takes multiple forms.
There are two forms of polymorphism :
There are two forms of polymorphism :
- Compile time Polymorphism
- Run time Polymorphism
Compile time polymerphism
Compile time polymorphism is achieved using method overloading. Method will have same signaturre(name) but different parameters.This method is bound statically with method name and input parameter type hence static binding.
Output :
Display String Display int
Runtime Polymorphism
Method overriding is used to achieve Runtime polymorphism. Method will be overridden in subclass. This method is resolved depending on Object instance dynamically at runtime.
Output :
Display of Display Unit. Display of Monitor.

Comments
Post a Comment