aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertions" Watch "Assertions" New topic
Author

Assertions

Padmavathi Narayana
Greenhorn

Joined: Jun 16, 2003
Posts: 12
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.
Padmavathi Narayana
Greenhorn

Joined: Jun 16, 2003
Posts: 12
Sorry, neglet it. I realized my mistake here!!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Assertions