Home » Core Java » Method Overloading in Java

Method Overloading in Java

Polymorphism is another important Object oriented concept in Java programming language.The Word Polymorphism comes from the greek roots “poly” (many) and “morphe” (form).Therefore ,If an object is polymorphic ,then it can take many forms.Similary a polymorphic method can also take many forms.

There are 2 types of polymorphism in java .

1 : Compile time polymorphism (static polymorphism)

2 : Runtime polymorhism( Dynamic polymorphism)  

In java ,method overloading is an example of compile time polymorphism and method overriding is an example of run time polymorphism.
Method OverLoading :
If there are more than one method with same name but with different parameters in a class , then it is called method overloading.

Example :
In the below example, method outputName() is overloaded.The first example take one argument and returns only first Name and the second method example takes two
arguments and both complete Name(concatenation of first name and last name)

How to overload a method ?
1 : By changing the data type of the argument
2 : By changing the number of arguments
3 : By changing the order of arguments

Example :

OutPut :


Please note that return type of the method does not play any role in method overloading.

Leave a comment

Your email address will not be published. Required fields are marked *

8 + 11 =