问题:
public class Test {
public static void main(String[] args) {
int x = 0;
assert (x > 0): “assertion failed”;
System.out.println(“finished”);
}
}
What is the result?()
A . finished
B . Compilation fails.
C . An AssertionError is thrown.
D . An AssertionError is thrown and finished is output.
public class Test {
public static void main(String[] args) {
int x = 0;
assert (x > 0): “assertion failed”;
System.out.println(“finished”);
}
}
What is the result?()
● 参考解析
This question is a bit tricky because it lacks the following information: It should include a statement that says whether or not assertions are enabled. If they are indeed enabled, the
correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.