考虑以下 Java 类:
public class Animal {
public static void printText(Object obj) {
System.out.println(obj.toString());
}
}
class Tiger extends Animal {
// Contains some unimportant methods.
}
现在,当在 main 方法中输入以下内容时,即使强制转换会导致错误,编译器也不会给出任何错误。为什么?
public static void main(String[] args) {
Animal animal = new Animal();
((Tiger)animal).printText(animal); // <= ?? no error in the compiler ??
}