方法重载
方法重载与什么因素有关
1:参数个数不同
2:参数类型不同
3:参数的多类型顺序不同
参数个数不同的重载
重载类型不同
多类型顺序不同
方法重载与下列因素无关
1:与参数名称无关
2:与方法的返回值类型无关
与参数名称无关
与方法的返回值类型无关
方法重载的练习
//方法重载练习题1
public static void main(String[] args) {
System.out.println(issame((byte) 10, (byte) 20));
System.out.println(issame(10, 20));
System.out.println(issame(10l, 10l));
System.out.println(issame((short) 10, (short) 20));
}
public static boolean issame(byte a, byte b) {
System.out.println("执行byte判断");
boolean same;
if (a == b) {
same = true;
} else {
same = false;
}
return same;
}
public static boolean issame(int a, int b) {
System.out.println("执行int判断");
boolean same;
return a == b;
}
public static boolean isssame(short a, short b) {
System.out.println("执行double判断");
boolean same = a == b ? true : false;
return same;
}
public static boolean issame(long a, long b) {
System.out.println("执行long判断");
if (a == b) {
return true;
} else {
return false;
}
}
习题2 判断那些不是重载