面向对象程序设计(Java) chapter12

1.A Java exception is an instance of __________.
单选题 (2 分)
E
A.Exception

B.RuntimeException

C.Error

D.NumberFormatException

E.Throwable
3.
Analyze the following code:

class Test {

public static void main(String[] args) {

try {

  String s = "5.6";

  Integer.parseInt(s); // Cause a NumberFormatException

  int i = 0;

  int y = 2 / i;

}

catch (Exception ex) {

  System.out.println("NumberFormatException");

}

catch (RuntimeException ex) {

  System.out.println("RuntimeException");

}

}

}
单选题 (2 分)
D
A.The program displays NumberFormatException followed by RuntimeException.

B.The program displays NumberFormatException.

C.The program displays RuntimeException.

D.The program has a compilation error.
4.Which class do you use to read data from a text file?
单选题 (2 分)
C
A.PrintWriter

B.System

C.Scanner

D.File
6.
What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

  System.out.println("Welcome to Java");

  int i = 0;

  int y = 2/i;

  System.out.println("Welcome to Java");

}

finally {

  System.out.println("End of the block");

}

System.out.println("End of the block");

}

}
单选题 (2 分)
D
A.The program displays Welcome to Java two times followed by End of the block.

B.The program displays Welcome to Java two times followed by End of the block two times.

C.The program displays Welcome to Java three times followed by End of the block.

D.The program displays Welcome to Java and End of the block, and then terminates(终止) because of an unhandled(未处理的) exception(异常).
7.
What is displayed on the console when running the following program?

class Test {

public static void main(String[] args) {

try {

  method();

  System.out.println("After the method call");

}

catch (RuntimeException ex) {

  System.out.println("RuntimeException");

}

catch (Exception ex) {

  System.out.println("Exception");

}

}

static void method() throws Exception {

try {

  String s = "5.6";

  Integer.parseInt(s); // Cause a NumberFormatException

  int i = 0;

  int y = 2 / i;

  System.out.println("Welcome to Java");

}

catch (RuntimeException ex) {

  System.out.println("RuntimeException");

}

catch (Exception ex) {

  System.out.println("Exception");

}

}

}
单选题 (2 分)
E
A.The program has a compilation error.

B.The program displays Exception followed by RuntimeException.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值