The overload of a method is to allow more than one method of the same name to exist in the same class, as long as they have a different number of arguments or types. In this case, the method is called overloaded, and this process is called the overloading of the method.
Example: Testjava4_11.java
01//The following procedure describes the overloaded operation of the method
public class Testjava4_11
03 {
public static void Main (string[] args)
05 {
Int_sum int;
-Double double_sum;
Int_sum = Add (3,5); Call the Add method with two parameters
The value of System.out.println ("Int_sum = Add (3,5) is:" +int_sum);
Ten int_sum = Add (3,5,6); Call the Add method with three parameters
One System.out.println (the value of "Int_sum = Add (3,5,6) is:" +int_sum);
Double_sum = Add (3.2,6.5); The value passed in is Doule type
The value of System.out.println ("Double_sum = Add (3.2,6.5) is:" +double_sum);
14}
public static int Add (int x,int y)
16 {
X+y return;
18}
public static int Add (int x,int y,int z)
20 {
return x+y+z;
22}
All public static double add (double x,double y)
24 {
return x+y;
26}
27}
Output Result:
The value of Int_sum = Add (3,5) is: 8
The value of Int_sum = Add (3,5,6) is: 14
The value of Double_sum = Add (3.2,6.5) is: 9.7
It can be found that the add is overloaded three times, but each overloaded method can accept the number of parameters and the type of different, I believe the reader should now be able to understand the concept of method overloading.
Well-off accompany you to learn Java--------overload