问题 单项选择题

下面程序输出的结果是什么 ( )
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.无输出

答案

参考答案:C

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

单项选择题
单项选择题 A1/A2型题