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 :

  1. Compile time Polymorphism
  2. 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

Popular posts from this blog

How to do AJAX using XMLHttpRequest for large data

Caching mechanisms in modern world browser