Tuesday, 17 November 2015

What is Polymorphism ? Give an example of Static polymorphism and Dynamic polymorphism

Polymorphism means ability to take more than one form. It is briefly described as "one interface, many implementations."

Polymorphism is categorized in to 2 types :

1. Static Polymorphism (Ex: Overloading) : Method name should be same but different arguments. The method resolution will take place based on the reference type.

2. Dynamic Polymorphism (Ex: Overriding) : Method name , arguments, return type should be same up to java 4. Java 5 onwards Covariant return types are allowed. Method resolution take place based on the object type
Example of  Overloading :

 

Example of Overriding :

No comments:

Post a Comment