thinking in java中关于异常的一点疑问
如果类A在扩展类B的同时又实现了接口C,且B与C有相同方法event,但各自抛出不同的异常,那么接口的event()方法就不能改变在基类中的event()方法的异常接口。否则的话,使用基类的时候就不能判断是否捕获了正确的异常。这段话怎么理解?
接口:Storm .基类:Inning 以及子类 StormInning,如下,对于StormInning的event方法,抛出RainedOut和BaseException都会报错。
interface Storm{
public void event() throws RainedOut;
}
class Inning{
public void event() throws BaseException;
}
class StormInning extends Inning implements RainedOut{
public void event() /*throws RainedOut*/{
}
}