OCA Java SE 8 Operators/Statements - OCA Mock Question Operator and Statement 6








Question

What is the output of the following code snippet?

     3: do { 
     4:   int x = 1; 
     5:   System.out.print(x++ + " "); 
     6: } while(x <= 10); 
     
  1. 1 2 3 4 5 6 7 8 9 10
  2. 1 2 3 4 5 6 7 8 9
  3. 1 2 3 4 5 6 7 8 9 10 11
  4. The code will not compile because of line 6.




Answer



D.

Note

The variable x is declared within the do-while statement, so it is out of scope on line 6.