Polymorphism in Java

'Poly' means Multiple 'morphs' means forms.
we can have multiple forms of same action.

There are two basic types of polymorphism

1) Compile Time Polymorphism :-
it is also known as static binding or early binding.
we can use same name to functions with different parameters within same class.
It is known as "Method Overloading".
In this case, compiler will understand which method (function) to call by the number and type of parameters passed through the method (function).

2) Run Time Polymorphism:-
it is also known as Dynamic binding or late binding.
we can use same name function with same parameters in base class and derived class
It is known as "Method Overriding".
In this case, reference variable of base class is created and then object of respective class is assigned to that reference variable by that way compiler will understand which method to call, either from base class or from derived class.


click here for example:-
Example of Method Overriding

Comments