方法的重载
方法的重载在于通过不同的形参调用不同的方法(形参的个数,类型等不同),这样可以随时调用自己想要的方法
public class TestOverload {
public static void main(String[] args) {
System.out.println(add(40, 50));
System.out.println(add(10, 20, 30));
}
public static int add(int n1, int n2) {
int sum = n1 + n2;
return sum;
}
public static int add(int n1, int n2, int n3) {
int sum = n1 + n2 + n3;
return sum;
}

浙公网安备 33010602011771号