您的位置:首页 > 其它

子类重写父类的方法时声明抛出异常不能比父类范围大

2014-03-15 14:09 309 查看
public class JavaTest {public static void main(String[] args) {Parent child=new Child();try {child.test();} catch (MyException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}class MyException extends Exception{/****/private static final long serialVersionUID = 1L;public MyException() {super();}public MyException(String msg){super(msg);}}class Parent{private Parent parent;public Parent() {// TODO Auto-generated constructor stub}public Parent(Parent parent){this.parent=parent;}void test() throws MyException{}}class Child extends Parent{public Child(Parent parent) {super(parent);// TODO Auto-generated constructor stub}Child(){}void test() throws MyException{}}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: