一道关于异常的题目

lovecj6185 2009-06-24 10:37:16

class p16 extends Tire{
public static void main(String[] args){
new p16().doStuff();
}

// insert code here -->line 10
System.out.println(7/0);
}

}

class MyException extends Exception{}
class Tire{
void doStuff(){}
}


And given the following four code fragments:

1.void doStuff(){

2.void doStuff() throws MyException{

3.void doStuff() throws RuntimeException{

4.void doStuff() throws ArithmeticException{


When fragments 1-4 are added, independently, at line 10, which are true?(choose all that apply)

A. None will compile

B. They will all compile

C. Some, but not all, will compile

D. All of those that compile will throw an exception at runtime

E. None of those that compile will throw an exception at runtime

F. Only some of those that compile will throw an exception at runtime

答案为 C D

答案C可以理解。
但是不明白D,或许我没有理解D答案的意思
请各位高手指教
...全文
37 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lovecj6185 2009-06-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 knightzhuwei 的回复:]
d的意思是能通过编译的那些运行时会抛出异常
[/Quote]

原来如此
谢谢,明白了
rumlee 2009-06-24
  • 打赏
  • 举报
回复
哦,没有看到除数为0,晕倒。
rumlee 2009-06-24
  • 打赏
  • 举报
回复
个人觉得答案应该是C、E才是啊。

应该不会抛出异常才是。
Pike_Jun 2009-06-24
  • 打赏
  • 举报
回复
D. All of those that compile will throw an exception at runtime
意思是所有编译通过的程序在运行时会抛出异常。7/0异常。
knightzhuwei 2009-06-24
  • 打赏
  • 举报
回复
被0除的异常没有捕获的话肯定是要抛异常的啊
knightzhuwei 2009-06-24
  • 打赏
  • 举报
回复
1 能通过编译 但是运行时抛异常
2 无法通过编译 重写的方法不能抛出更多非运行时异常
3 能通过编译 但是运行时抛异常
4 能通过编译 ArithmeticException extends RuntimeException
但是运行时抛异常
knightzhuwei 2009-06-24
  • 打赏
  • 举报
回复
d的意思是能通过编译的那些运行时会抛出异常

62,615

社区成员

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

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