异常的封装及注意事项

来源:互联网 发布:网络购彩何时恢复 编辑:程序博客网 时间:2024/05/07 05:41


1.classA extends Exception

{}

classB extends A

{}

classC extends Exception

{}

classFu

{

   void show() throws A

}

classZi

{

       void show() throws A// thows B也可以,throws C不可以

}

2.interface A

  {

    void show();

}

classB implements A

{

voidshow () thows C//是错误的,父类方法没有异常时,子类覆盖时绝对不能抛,只能try。

}


0 0
原创粉丝点击