子类中的一个方法可以覆盖父类中的一个方法,并在父类方法没有抛出异常时抛出运行时异常吗?就像这样:
class X { public void foo() { System.out.print("X "); } }
public class SubB extends X {
public void foo() throws RuntimeException {
super.foo();
if (true)
throw new RuntimeException();
System.out.print("B ");
}
public static void main(String[] args) {
new SubB().foo();
}
}