62,614
社区成员
发帖
与我相关
我的任务
分享
class Ex05_p82_5_2_3 {
/*
public static void f() {
System.out.println("f()");
}
//compile error: 已在类中定义了方法f()
public static int f() {
return 1;
}
*/
public static int add(int x, int y) {
return x + y;
}
public static String add(String str1, String str2) {
return str1 + str2;
}
public static void main(String [] args) {
String c = add("a", "b");
System.out.println(c);
int x = add(1,1);
System.out.println(x);
}
}
这里个人认为应该理解为:不能单单依靠返回值类型来区分方法重载。