Java OCA OCP Practice Question 258

Question

Given:

3. public class Main {
4.   public static void main(String[] args) {
5.     int j = 7;
6.     assert(++j > 7);
7.     assert(++j > 8): "hi";
8.     assert(j > 10): j=12;
9.     assert(j==12): doStuff();
10.     assert(j==12): new Main();
11.   }/*  www .  j  a  va  2 s  .  com*/
12.   static void doStuff() { }
13. }

Which are true?

Choose all that apply.

  • A. Compilation succeeds
  • B. Compilation fails due to an error on line 6
  • C. Compilation fails due to an error on line 7
  • D. Compilation fails due to an error on line 8
  • E. Compilation fails due to an error on line 9
  • F. Compilation fails due to an error on line 10


E is correct.

Note

When an assert statement has two expressions, the second expression must return a value.

The only two-expression assert statement that doesn't return a value is on line 9.




PreviousNext

Related