Polymorphism in Java
polymorphism = poly + morphism
poly means many. morph means forms. So polymorphism means many forms.
In OOPs, polymorphism means a method of different or many forms.
Polymorphism is achieved using method overloading and overriding concepts.
Method overloading is overwriting a method with the same method name but varying in parameter part.
We can overload a method
- By varying in number of parameters.
- By varying in datatype of the parameters.
Method overriding is re-writing the implementation of a existing method of a parent class in subclass.
In other words, it is just overwriting an implementation of a existing method of a parent class in subclass.
You will learn detailly about method overloading and overriding in next topics.