Java OCA OCP Practice Question 781

Question

Which lines can be removed together without stopping the code from compiling and while printing the same output? (Choose three.)

14:  String s = ""; 
15:  outer: 
16:  do { 
17:  inner: 
18:     do { 
19:        s += "x"; 
20:     } while (s.length() <= 4); 
21:  } while (s.length() < 4); 
22: System.out.println(s); 
  • A. Lines 15 and 17
  • B. Lines 15, 16, and 21
  • C. Line 17
  • D. Lines 17, 18, and 20
  • E. Line 20
  • F. Line 21


A, B, C.

Note

Option A is correct because the labels are not referenced.

Option B is correct because the outer while is broader than the inner while.

Since there is no other code in the loop, it is not needed.

Option C is also correct because a label is not used.

Option D is incorrect because the inner loop is more specific than the outer loop.

Options E and F are incorrect because you cannot remove one half of a loop construct and have it compile.




PreviousNext

Related