我知道如果方法覆盖对象被检查而不是类型
class SuperException extends Exception {}
class SubException extends SuperException {}
class AnotherException extends Exception {}
class YetAnotherException extends Exception {}
class A {
void play() throws SuperException, AnotherException {}
}
class Reduced extends A {
void play() throws SuperException {}
}
class Eliminated extends A {
void play() {}
}
class Narrower extends A {
void play() throws SubException {}
}
class TestPolymorphism {
public static void main(String[] args) {
A obj = new Eliminated();
obj.play(); // Doubt 1
Eliminated eobj = new Eliminated(); // Doubt 2
}
}
疑问1:为什么play()是从A类引用的?
疑问2:为什么会出现编译错误?