Examveda
Examveda

What all gets printed when the following program is compiled and run.
public class Test{
      public static void main(String args[]){ 
            int i, j=1;
            i = (j>1)?2:1;
            switch(i){
                  case 0: System.out.println(0); break;
                  case 1: System.out.println(1);
                  case 2: System.out.println(2); break;
                  case 3: System.out.println(3); break;
            }
      }
}

A. 0

B. 1

C. 2

D. 3

E. 1 2

Answer: Option E


This Question Belongs to Java Program >> Flow Control

Join The Discussion

Comments ( 1 )

  1. Ram Ran
    Ram Ran :
    7 years ago

    j>1 is false so i=1
    switch statement switch(1)
    case 1 is execute and not used break statement for case 1.
    so case 2 also executed
    now case 1 print :1
    case 2 print:2
    output should be 1 2

Related Questions on Flow Control