A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

What is Polymorphism?

Polymorphism in Java

What is Polymorphism in Java?

This ability of different objects to respond each in its own way to identical messages is called polymorphism. Polymorphism results from the fact that every class lives in its own namespace. The names assigned within a class definition won't conflict with names assigned anywhere outside it. This is true both of the instance variables in an object's data structure and of the object's methods:


Just as the fields of a C structure are in a protected namespace so are an object's instance variables. Method names are also protected. Unlike the names of C functions method names aren't global symbols. The name of a method in one class can't conflict with method names in other classes; two very different classes could implement identically named methods.


Method names are part of an object's interface. When a message is sent requesting an object to do something the message names the method the object should perform. Because different objects can have different methods with the same name the meaning of a message must be understood relative to the particular object that receives the message. The same message sent to two different objects could invoke two different methods.


The main benefit of polymorphism is that it simplifies the programming interface. It permits conventions to be established that can be reused in class after class. Instead of inventing a new name for each new function you add to a program the same names can be reused. The programming interface can be described as a set of abstract behaviours quite apart from the classes that implement them.
Example: polymorphism method(Overloading)
example: polymorphism method(Overriding)

LEARN TUTORIALS

.

.