Java 方法重载(Overload)

140 阅读1分钟

内容

  1. 方法名相同,参数类型不同
  2. 参数的个数不同
  3. 返回值也可以不同

用例

public class MethodOverload {
    public static void main(String[] args) {
        System.out.println(method(1));
        System.out.println(method(1.2,2.3));
        System.out.println(method(1,3));
        method();

    }
    public static int method(int a){
        return 1;
    }
    public static double method(double a,double b){
        return 1.11;
    }
    public static int method(int a, int b){
        return 2;
    }
    public static void method(){
        System.out.println("丽");
    }
}