method overloads:Method overloading is the method name repetition and loading parameters are different.
Specific Specifications:
I. The method name must be the same. Two. The parameter table of the method must be different, including the type or number of parameters, to distinguish between different method bodies. 1. If the number of parameters is different, regardless of its parameter type! 2. If the number of arguments is the same, then the order of the parameters must be different. Three. The method's return type, modifiers can be the same, or different.
Examples of overloading include the ability to add two integers, add three integers, and add two decimals in code.
public class Example17 {public static void main (string[] args) {///The following is a call to the summation method int sum1 = Add (1, 2); int sum2 = Add (1, 2, 3 );d ouble sum3 = Add (1.2, 2.3);//The following code is the result of printing the sum System.out.println ("sum1=" + sum1); System.out.println ("sum2=" + sum2); System.out.println ("sum3=" + sum3);} The following method implements the addition of two integers public static int add (int x, int y) {return x + y;} The following method implements the addition of three integers public static int add (int x, int y, int z) {return x + y + z;} The following method implements two decimals added public static double add (double x, double y) {return x + y;}}
The results are as follows:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java_se basic--17. Overloading of methods