Polymorphism
Polymorphism is the ability of an object to take
on many forms. The most common use of polymorphism in OOP occurs when a parent
class reference is used to refer to a child class object. Polymorphism is
derived from 2 greek words: poly and morphs. The
word "poly" means many and "morphs" means forms. So
polymorphism means many forms.
Real
life example of polymorphism
Suppose if you are in class room that time you behave like a
student, when you are in market at that time you behave like a customer, when
you at your home at that time you behave like a son or daughter, Here one
person present in different-different behaviors.
How to
achieve Polymorphism in Java ?
In java programming the Polymorphism principal is implemented with
method overriding concept of java.
Polymorphism principal is divided into two sub principal they are:
Ø Static or
Compile time polymorphism
Ø Dynamic
or Runtime polymorphism
Let us
consider the following diagram
Here original form or original method always resides in base class
and multiple forms represents overridden method which resides in derived
classes.
In the above diagram the sum method which is present in BC class
is called original form and the sum() method which are present in DC1 and DC2
are called overridden form hence Sum() method is originally available in only
one form and it is further implemented in multiple forms. Hence Sum() method is
one of the polymorphism method.
Comments
Post a Comment