What Is Polymorphism In Java ?
Posted on December 19, 2009
Question: What Is Polymorphism In Java ?
Answer :- Polymorphism is a feature that allows one interface to be used for a general class of actions. The specific action is determined by the exact nature of the situation. Consider a stack (Which is a last-in, first-out list).you might have a program that requires three types of stacks. One stack is used for integer value, one for floating-point values, and one for characters.
The algorithm that implements each stack is the same, even though the data being stored differs. In a non-object-oriented language, you would be required to create three different sets of stack routines, with each set using different names. However, because of polymorphism, in java you can specify a general set of stack routines that all share the same names.
More generally the concept of polymorphism is often expressed by the phrase” one interface, multiple methods”. This means that it is possible to design a generic interface to a group of related activities. This helps reduce complexity by allowing the same interface to be used to specify a general class of action. It is the compiler’s job to select the specific action as it applies to each situation. You the programmer do not need to make this selection manually. You need only remember and utilize the general interface.
Polymorphism is a simple concept that you understand right now, as it is prevalent through life. You are a person, which person is a base type and you are a more specific representation of that type. There are many people that inherit that type, of which you are a concrete implementation of that type: you have your own beliefs, attributes, and qualities that go beyond just a general person. For instance, we all have a blood type, shoe size, arm length, and many other properties. But we each add our own implementation to the person interface.
Polymorphism is the ability that helps in executing different operations in response to the same message. In Object-Oriented Programming (OOP’s) you can implement polymorphism by creating more than one function within a class that have the same name. Polymorphism can either be static or dynamic. You can apply polymorphism for reducing the complexity within the functions of a class of you program.
Looking for a Fresher Job? Post Your Resume Free !!!
More Articles From "Java" Category
- What is Collection API in Java?
- What is Abstraction in Java ?
- What is Inheritance in Java ?
- What Is Java Virtual Machine or JVM ?
- What Is Java Garbage Collection ?
- What Is Java Technology?