Sunday, August 15, 2010

Assertions: Bold.java

Courtesy of Sun Web Learning Center

 7. class Bold {
 8.   public static void main(String[] args) {
 9.     Boolean boo = true;
10.     assert(!boo): "yee ";
11.     System.out.println("haw ");
12.   }
13. }

And the command line invocation: java Bold What is the result?

A     yee with no errors
B     haw with no errors
C     yee haw with no errors
D     An Assertion error including yee in the output
E     An Assertion error including haw in the output
F     An Assertion error with neither yee or haw in the output


B is correct. Assertions were not enabled when the class was invoked.

No comments:

Post a Comment