The Java programming language supports overloading methods, and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists
- In the Java programming language, you can use the same name for all the drawing methods but pass a different argument list to each method. Thus, the data drawing class might declare four methods named draw, each of which has a different parameter list.
- Overloaded methods are differentiated by the number and the type of the arguments passed into the method
Example
public class Main {
static int Intmethod(int x, int y) {
return x + y;
}
static double Doublemethod(double x, double y) {
return x + y;
}
public static void main(String[] args) {
int myNum1 = Intmethod(5, 5);
double myNum2 = Doublemethod(5.3, 6.26);
System.out.println("int: " + myNum1);
System.out.println("double: " + myNum2);
}
}
Output
int: 10
double: 11.559999999999999