Java OCA OCP Practice Question 1103

Question

What happens when running the following code?

do ( 
   System.out.println("aaa"); 
) while (false); 
  • A. It completes successfully without output.
  • B. It outputs helium once.
  • C. It keeps outputting helium.
  • D. The code does not compile.


D.

Note

Braces are optional around loops if there is only one statement.

Parentheses are not allowed to surround a loop body though, so the code does not compile, and Option D is correct.




PreviousNext

Related