Object Oriented Programming

Java Polymorphism

In Greek, Poly means many and Morph means shape or form.
Polymorphism means many forms
Java utilizes the concept of polymorphism to invoke method(having same name) for different purposes.
Doing this increases the readability of the program.
For example, We can use method 'perimeter' to find the perimeter of cube, rectangle, circle, and other shapes. 
Now had we used different method names like say A to find perimeter of circle, B to find perimeter of rectangle and so on then the readability would have been hamphered. As seeing these kind of method names we cannot undersatand the purpose of the method. 
But when we use same name as perimeter, by seeing we can make out that the method will calculate the perimeter.
Every objects in java that has IS-A relationship is polymorphic.
In java we have two types of polymorphism:
  • Compile time polymorphism or method overloading
  • Run time polymorphism or Dynamic method dispatch or method overriding
We will learn both method overloading and overriding in details with examples in the respective chapters.

Please Share this page
Views : 50