Monday, 4 September 2017

Polymorphism in Java

The word Polymorphism means of many forms.

Polymorphism is an object-oriented programming concept that refers to the ability of a variable, function or object to take on multiple forms.

Same method when applied on different objects gives different result.

Suppose if you are in class room that time you act like a student, when you are in market at that time you act like a customer, when you at your home at that time you behave like a son or daughter, Here one person there in different-different behaviors.

Two types of Polymorphism in java

Compile time polymorphism is not anything but the method overloading in java.

In simple conditions we can say that a class can have more than one method with same name but with different number of arguments or different types of arguments or both. To know more about it refers method overloading in java.

In Compile time Polymorphism, call is determined by the compiler.

It is reached by function overloading and operator overloading.

It provides fast execution as known early on at compile time.

Compile time polymorphism is fewer flexible as all things execute at compile time.

It is also known as Static binding, Early binding and overloading as well.

Method overriding is a ideal example of  runtime polymorphism.

Since in method overriding both the classes(base class and child class) have same method, compile doesn’t figure out which method to call at compile-time. In this case JVM(java virtual machine) decides which method, To know more about it refers method overiding in java.

In Run time Polymorphism, call is not determined by the compiler.

It is reached by virtual functions and pointers.

It offers slow execution as compare to early binding because it is known at runtime.

Run time polymorphism is additional flexible as all things execute at run time.

It is also known as Dynamic binding, Late binding and overriding as well.


  1. • Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updatingAzure Online Training