Sunday, August 15, 2010

Assertions: MoreAsserts.java

Courtesy of Sun Web Learning Center

1. class MoreAsserts {
2.   static int x = 5;
3.   public static void main(String [] args) {
4.     assert(doStuff(42));
5.     if(x < 40) ;
6.     else assert(false);
7.   }
8.   public static boolean doStuff(int arg) {
9.     assert(arg < x++);
10.     return false;
11.   }
12. }

Which is true?

A     None of the assert statements are appropriate.
B     The assert statement on line 4 is appropriate.
C     The assert statement on line 6 is appropriate.
D     The assert statement on line 9 is appropriate.
E     All three of the assert statements are appropriate.

No comments:

Post a Comment