Method Overloading In Java

Core Java Tutorial

[fblike]

Method Overloading In Java : Introduction

  • Since now we are done with the concepts of methods, objects and classes. Now we will look at what method overloading in java actually is.
  • Method overloading in Java is the technique to define more than one methods of the same name which are differentiated by their parameters list.
  • The criteria for differentiating parameters list of overloaded method is their type and number i.e. in method overloading parameters are differentiated by their type and their number.
  • Didn’t get the point yet? Don’t worry, go through the example below and all of your doubts will get clear.

 

Method Overloading In Java : Example

  • Let’s see an example of method overloading in java in the form of a program along with its output.

 

This image describes the sample program for method overloading in java.

Method Overloading In Java : Example

 

Output

 

This image describes the output of the sample program for method overloading in java.

Method Overloading In Java : Output

 

Note : There is no role of method return type in method overloading. Overloaded methods can have different or same return type. The compiler differentiates between parameters of overloaded methods.