/子类重写的父类的方法其抛出的异常类型只能是被重写的方法的异常类型的子类或异常类型一样
public class TestOverride {
public static void main(String[] args) {
//创建对象是 是以 A 为声明的,所以编译时 A是虚拟机辨认的,A的异常范围只能是IO及IO以下
//所以B的异常范围只能比IO小或相等
A a = new B();
try {
a.method1();
}catch(IOException e) {
e.printStackTrace();
}
}
}
class A{
public void method1() throws IOException{
}
}
class B extends A{
public void method1() throws FileNotFoundException{
}
}