the question is from single topic Dan's exam abt assertions Q.#7
class C {
String m1(int i) {
switch (i) {
case 0: return "A";
case 1: return "B";
case 2: return "C";
default:
throw new AssertionError();
}
}
public static void main(String[] args) {
C c = new C();
for (int i = 0; i < 4; i++) {
System.out.print(c.m1(i));
}
}
}
Which statements are true?
a. With assertions enabled it prints "ABC" followed by an AssertionError message.
b. With assertions disabled it prints "ABC" followed by an AssertionError message.
c. Assertions should not be used within the default case of a switch statement.
d. In this code example an "assert" statement could not be used in place of the "throw" statement.
e. A compiler error is generated.
f. None of the above.
Ans: a,b,d
As a know, when assertion is disabled means it is same as running in jdk version less then 1.4
I ran it in jdk1.3.1 and got a compile time AssertionError not found. So is ans b is correct if my assumption is right.