对于下面的代码,我无法理解对重载函数的调用是如何进行的,谁能给我一个详细的解释,当分别使用 Side 和 Tail 引用创建对象时,如何进行重载函数调用。
interface Side {
String getSide();
}
class Head implements Side {
public String getSide() {
return "Head ";
}
}
class Tail implements Side {
public String getSide() {
return "Tail ";
}
}
class Coin {
public static void overload(Head side) {
System.out.print(side.getSide());
}
public static void overload(Tail side) {
System.out.print(side.getSide());
}
public static void overload(Side side) {
System.out.print("Side ");
}
public static void overload(Object side) {
System.out.print("Object ");
}
public static void main(String[] args) {
Side firstAttempt = new Head();
Tail secondAttempt = new Tail();
overload(firstAttempt);
overload((Object) firstAttempt);
overload(secondAttempt);
overload((Side) secondAttempt);
}
}