Java – Method overloading

Java – Method overloading 2017-08-09T10:46:23+00:00

Java Method overloading :

Method overloading:

A class can contain any number of methods. Methods can be with parameter and without parameter.

The parameter in a method are called type signature.

It is possible in java to define two or more methods within the same class that share the same name, but with different parameter declarations (type signatures).

When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading.

Overloading methods demonstrate the concept of polymorphism.

When an overloaded method is invoked, java uses the type and/or number of arguments as its guide to determine which version of the overloaded method to call.

Thus, overloaded methods must differ in the type and/or number of their parameters.

Overloaded methods may have different return types.

When java encounters a call to an overloaded method, it simply executes the version of the method whose parameters match the arguments used in the call.

EX :



 


Output :
The Square is 200
The Square is 80
The Square is 56

You can see that here we have 3 square methods with different argument.

Its called method overloading.

Prev Next