一个关于异常的小问题

heaven_wsh 2010-03-12 10:04:12

public class AskAQuestion{
public static void main(String[] args){

}

void myException (int m) throws ArithmeticException{

}
}

class TestExtendsException extends AskAQuestion {
void myEception (int m) throws ArithmeticException,Exception{

}
}

继承的时候不是不能抛出更多的异常么???这样写为什么编译没有报错啊!!!
...全文
52 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
micsolaris 2010-03-13
  • 打赏
  • 举报
回复
异常不属于限定继承的范围,也就是说父类有抛出异常的方法,自己重写该方法的时候不一定要有抛出的方法。限制继承的只有 定义方法的关键字和方法的签名。
michaellufhl 2010-03-12
  • 打赏
  • 举报
回复
myEception 拼写错了:)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧