Home / Java Programming / Flow Control :: Discussion

Discussion :: Flow Control

  1. What will be the output of the program?

      int i = l, j = -1;
      switch (i) 
      {    
          case 0, 1: j = 1; /* Line 4 */ 
          case 2: j = 2;     
          default: j = 0;
     }
     System.out.println("j = " + j);  
    

  2. A.

    j = -1

    B.

    j = 0

    C.

    j = 1

    D.

    Compilation fails.

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    The case statement takes only a single argument. The case statement on line 4 is given two arguments so the compiler complains.


Be The First To Comment