方法重载

方法重载 

是在main函数中  输入不同类型的数 或内容  会同一方法名称 匹配不同运行且与之搭配的方法

// MethodOverload.java
// Using overloaded methods

public class MethodOverload {

public static void main(String[] args) {
System.out.println("The square of integer 7 is " + square(7));
System.out.println("\nThe 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/1983185414xpl/p/9786899.html