Java OCA OCP Practice Question 1095

Question

What is the result of the following code?

do { 
        int count = 0; 
        do { 
           count++; 
        } while (count < 2); 
           break; 
} while (true); 
System.out.println(count); 
  • A. 2
  • B. 3
  • C. The code does not compile.
  • D. This is an infinite loop.


C.

Note

At first this code appears to be an infinite loop.

The count variable is declared inside the loop.

It is not in scope after the loop where it is referenced by the println().

The code does not compile, and Option C is correct.




PreviousNext

Related