/*
子父类异常情况
(1)如果父类抛出了异常,子类重写父类方法时,抛出和父亲相同的异常或者父类异常的子类或者不抛异常
(2)父类方法没有抛出异常,子类重写父类方法时,也不可抛出异常,此时子类的异常需要使用try-catch处理,不可声明抛出
*/
public class Fu{
public void show01() throws NullPointerException{}
public void show02() throws IndexOutOfBoundsException{}
public void show03() throws IndexOutOfBoundsException{}
public void show04(){}
}
class Zi extends Fu{
//和父类方法抛出的异常一致
@Override
public void show01() throws NullPointerException { }
//抛出父类方法异常的子类异常
@Override
public void show02() throws ArrayIndexOutOfBoundsException{}
//不抛出异常
@Override
public void show03() {}
//使用try-catch捕获处理
@Override
public void show04() {
//如有异常使用try-catch处理
}
}