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.