package chapter04;
/*
问题:方法名太多了,不容易记忆,有时会出错
使用方法的重载(overload)来解决
*/
public class C09_Method {
public static void main(String[] args) {
int a = print();
// 如果不强转默认是int类型
Short s = (short) print(3);
double c = print(5);
String d = print("11");
System.out.println(a);
System.out.println(s);
System.out.println(c);
System.out.println(d);
}
public static int print() {
return 20;
}
public static short print(short a) {
return 1;
}
public static double print(double a) {
return 1.0;
}
public static String print(String name) {
return "name";
}
}
-------------------打印结果-------------------
20
1
1.0
name