动手动脑2

;
public class MethodOverload {

public static void main(String[] args) {
System.out.println("The square of integer 7 is " + square(7));
System.out.println(" The square of double 7.5 is " + square(7.5));
}

public static int square(int x) {
return x * x;
}

public static double square(double y) {
return y * y;
}
}

     答:代码中的两个方法,方法名相同,但返回值类型和参数类型都不同.。这又叫做重载。

原文地址:https://www.cnblogs.com/xiaojq/p/7664606.html