第十二章单元测试
  1. 关于异常,下列说法正确的是( )。

  2. A:异常是一种对象。 B:异常就是错误。 C:为了保证程序运行速度,要尽量避免异常。 D:一旦程序运行,异常将被创建 。
    答案:异常是一种对象。
  3. java中用来抛出异常的关键字是( )。

  4. A:catch B:finally C:try D:throw
  5. 当方法遇到异常又不知如何处理时,下列哪种说法是正确的( )。

  6. A:声明异常 B:嵌套异常 C:抛出异常 D:捕获异常
  7. ( )类是所有异常类的父类。

  8. A:Error B:Throwable C:Exception D:AWTError
  9. 下列哪种异常是检查型异常,需要在编写程序时声明( )。

  10. A:FileNotFoundException B:ClassCastException C:NullPointerException D:IndexOutOfBoundsException
  11. 以下关于异常的代码的执行结果是( )。
    public class Test {
        public static void main(String args[]) {
            try {
                System.out.print("try");
                return;
            } catch(Exception e){
                System.out.print("catch");
            }finally {
                System.out.print("finally");
            }
        }
    }


  12. A:try B:catch finally C:try catch finally D:try finally
  13. 在异常处理中,如释放资源、关闭文件等由( )来完成。

  14. A:catch子句 B:finally子句 C:throw子句 D:try子句
  15. 阅读如下Java代码,在控制台输入"-1",执行结果是( )。
    import java.util.InputMismatchException;
    import java.util.Scanner;
    public class Demo {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            System.out.print("请输入数字:");
            try {
                int num = input.nextInt();
                if (num < 1 || num > 4) {
                    throw new Exception("必须在1-4之间!");
                }
            } catch (InputMismatchException e) {
                System.out.println("InputMismatchException");
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
    }


  16. A:输出:必须在1-4之间! B:输出:InputMismatchException C:什么也没输出 D:编译错误
  17. 数组下标越界,则发生异常,提示为( )。

  18. A:ArrayIndexOutOfBoundsException B:IOException C:SQLException D:ArithmeticException
  19. 对于catch子句的排列,下列哪种是正确的( )。

  20. A:有继承关系的异常不能在同一个try程序段内 B:子类在先,父类在后 C:先有子类,其他如何排列都无关 D:父类在先,子类在后

温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!
点赞(1) dxwkbang
返回
顶部