下面程序输出的结果是什么? ( ) public class Quiz2 { public static void main(String args[]) { try {throw new My

admin2010-07-28  33

问题 下面程序输出的结果是什么?  (    )    public class Quiz2    {       public static void main(String args[])       {          try {throw new MyException();          }catch(Exception e)          {             System.out.println("It’s caught!");          }finally{             System.out.println("It’s finally caught!");          }       }    }    class MyExeeption extends Exception{}

选项 A、It’s finally caught!
B、It’s caught!
C、It’s caught!/It’sfinally caught!
D、无输出

答案4

解析 本题是对异常处理基本知识的考查。本程序中创建了一个异常类MyExce-ption,它的祖先类是Exception。在程序中,程序先发出异常MyException,下面是catch捕获异常,但是catch列表中并没有与之对应的MyException,但是有一个Exception,它是MyException的祖先类。如果有多种异常需要捕获,在安排catch语句的顺序时要注意,应该首先捕获最特殊的类,然后逐渐一般化。  例如,IOException类是 FileNotFoundException类的父类,就应该首先捕获FileNotFoundException异常,然后捕获IOException异常。所以运行结果是Ifs caught!/It’s finally caught!
转载请注明原文地址:https://kaotiyun.com/show/Zh9p777K
0

最新回复(0)