Java OCA OCP Practice Question 814

Question

What will be the result of attempting to compile and run the following code?

public class Main{ 
   public static void main (String args []){ 
      for  ( int i = 0 ; i < 3 ; i++){ 
         boolean flag  = false; 
         switch  (i){ 
            flag  = true; /*from w ww.jav  a  2s  .c  o  m*/
          } 
         if  ( flag )  System .out.println ( i ); 
       } 
    } 
} 

Select 1 option

  • A. It will print 0, 1 and 2.
  • B. It will not print anything.
  • C. Compilation error.
  • D. Runtime error.
  • E. None of the above.


Correct Option is  : C

Note

You cannot have unlabeled block of code inside a switch block.




PreviousNext

Related