一题JAVA基础题~~~请教一下各位,望高人指点

dirkkovacevic 2006-06-07 02:36:43
Given:
public class ExceptionTest {
class TestException extends Exception {}
public void runTest () throws TestException {}
public void test () /* Point X*/ {
runTest ();
}
}
At point X on line 4, which code can be added to make the code
compile?
A.throws Exception
B.catch (Exception e)
C.throws RuntimeException
D.catch (TestException e)
E.no code is necessary

我自己选了A 但是不知道对不对~~~请指教~~谢谢
...全文
217 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
billdavid 2006-06-07
  • 打赏
  • 举报
回复
You're right.
If you are not sure, why not compile it?
User defined exception must be caught or declared, when declaring it, use throws.
Camelh 2006-06-07
  • 打赏
  • 举报
回复
由于runTest 跑出的异常是TestException ;所以在test()中只能抛出TestException 或者它的父类异常;即在test方法中抛出的异常范围不能超过其方法体中可能抛出异常的范围;
dirkkovacevic 2006-06-07
  • 打赏
  • 举报
回复
请问,大家可以给个答复一下吗??
T_T
kevinliuu 2006-06-07
  • 打赏
  • 举报
回复
ok

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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