scjp真题请教....

w19995 2002-01-16 07:02:50
import java.io.IOException;
public class ExceptionTest{
public static void main(String[] args){
try{
methodA();
}catch(IOException e){
System.out.println("Caught IOException");
}catch(Exception e){
System.out.println("Caught Exception");
}
}
public static void methodA(){
throw new IOException();
}
请问这个程序应该输出什么呢?有人能讲出原因吗?
...全文
169 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
Patrick_DK 2002-01-18
  • 打赏
  • 举报
回复
C E

猜的
w19995 2002-01-18
  • 打赏
  • 举报
回复
再来一道真题:
Which two CANNOT directly cause a thread to stop execting?(choose two)
a,calling the yield method;
b,calling the wait method on an object;
c,calling the notify method on an object;
d,calling the notifyAll method on an object;
e,calling the start method on another Thread object;

请高手指点一二。
forest 2002-01-18
  • 打赏
  • 举报
回复
这道题有三点值得注意的:
1.在方法体内如果抛出了异常而又不想在该方法体内处理的化,必须再次抛出。
public static void methodA() throws Exception
{
throw new IOException();
}


2.如果catch块根本不可能捕获到异常的化,编译会出错。

3.如果try对应了多个catch块,程序会寻找第一个匹配的块,然后直接跳到finally(如果有的话)。对于其他块将不作处理。
leo1026 2002-01-17
  • 打赏
  • 举报
回复
而且少了一个括号
Patrick_DK 2002-01-17
  • 打赏
  • 举报
回复
就是麻,和我的意思一样


inzaghizxy 2002-01-17
  • 打赏
  • 举报
回复
agree with maqinglong_2000.
maqinglong_2000 2002-01-17
  • 打赏
  • 举报
回复
methodA()改成
public static void methodA() throws Exception
{
throw new IOException();
}
输出Caught IOException
Patrick_DK 2002-01-17
  • 打赏
  • 举报
回复
to hailong326(天水蓝) 

你的意思是??????????
maqinglong_2000 2002-01-17
  • 打赏
  • 举报
回复
Caught Exception
hailong326 2002-01-17
  • 打赏
  • 举报
回复
静态与非静态呀!!!
Patrick_DK 2002-01-17
  • 打赏
  • 举报
回复
这么解释总可以了吧
lxj_guitar 2002-01-16
  • 打赏
  • 举报
回复
编译出错!Exception java.io.IOExecption 在try语句中永远不会被抛出
methodA()方法后面应该有throws IOException
public static void methodA() throws IOException{
throw new IOException();
}
这样编译就可以通过了
Patrick_DK 2002-01-16
  • 打赏
  • 举报
回复
看清楚了,也编译试过了,这道题编译不通过,没有在methodA()处理或者再抛出异常
w19995 2002-01-16
  • 打赏
  • 举报
回复
这个题目不是那么简单的吧,大家多想想。
Patrick_DK 2002-01-16
  • 打赏
  • 举报
回复
catch可以有多个,但是必须保证“逆向”
~~~~

即先有异常子类,再有父类

如果反过来的话,你试试看,编译都通不过


当一个异常被捕捉处理后,下面的catch就不会再捕捉它了
Patrick_DK 2002-01-16
  • 打赏
  • 举报
回复
Caugth IOException

23,409

社区成员

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

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