What is Polymorphism in JAVA with example, Computer, The Clairifiers

What is Polymorphism in JAVA?

Polymorphism (poly = many, morphism = phase) allows two or more classes to respond to the same message in different ways. This means that you can use the same name for a method in two different classes or the same class. It also means that the user can send the same message to two different classes and still get the correct response. Polymorphism is the capability of an interface to do different things based on the data of different types it accepts and gives the desired output accordingly.

For example, when you are in the classroom you behave like a student, when you are in the market you behave like a customer and when you are at home you behave like a son or a daughter. Here one person presents different behaviours in different environments.

When properly applied, polymorphism, encapsulation, and inheritance combine to produce a programming environment that supports the development of far more robust and scalable programs than the process-oriented model.

A well-designed hierarchy of classes is the basis for reusing the code in which you have invested time and effort in developing and testing. Encapsulation allows you to migrate your implementations over time without breaking the code that depends on the public interface of your classes. Polymorphism allows you to create clean, sensible, readable, and resilient code.


Thank You So Much For Reading Till End!

Please share this post with your batch mates & whoever else needs this.

Post a Comment

Previous Post Next Post