第九章Java异常和异常处理

第九章Java异常和异常处理测验

1、单选题:
​给出如下代码段:‍​try { int x = Integer.parseInt("two"); }‍​下列哪个可以作为catch的异常?‍
选项:
A: ClassCastException
B: IllegalStateException
C: NumberFormatException
D: ExceptionInInitializerError
答案: 【 NumberFormatException

2、单选题:
‏给出下列代码:‌‏class Plane {‌‏    static String s = "-";‌‏    public static void main(String[] args){‌‏        new Plane().s1();‌‏        System.out.println(s);‌‏    }‌‏    void s1() {‌‏        try {s2();}catch (Exception e){‌‏         s += "c"; ‌‏        }‌‏    }‌‏    void s2() throws Exception {‌‏        s3(); ‌‏        s += "2";‌‏        s3();‌‏        s += "2b";‌‏    }‌‏    void s3() throws Exception{‌‏          throw new Exception();‌‏    }‌‏}‌‏结果是什么?‌‏‌
选项:
A: -
B: -c
C: -c2
D: -2c
答案: 【 -c

3、单选题:
‎下列程序的执行,说法正确的是( )‌‎class MultiCatch‌‎{‌‎     public static void main(String args[])‌‎    {‌‎        try‌‎        {‌‎              int a=args.length;‌‎              int b=42/a;‌‎              int c[]={1};‌‎              c[42]=99;  //10行‌‎              System.out.println(“b=”+b);‌‎      &nbs

剩余75%内容付费后可查看

发表评论

电子邮件地址不会被公开。 必填项已用*标注