Java OCA OCP Practice Question 1081

Question

What does the following code output?

int v = 0; 
while (v) 
   System.out.println(v++); 
  • A. 0
  • B. The code does not compile.
  • C. The loops complete with no output.
  • D. This is an infinite loop.


B.

Note

A while loop requires a boolean condition.

While v is a variable, it is not a boolean.

Therefore, the code does not compile, and Option B is correct.




PreviousNext

Related