Accenture Java Programming Practice Question
What will be the output of the program? int i = 1, j = -1; switch (i) { case 0, 1: j = 1; /* Line 4 */ case 2: j = 2; default: j = 0; } System.out.println("j = " + j);Answer options
A
j = 0
B
j = 1
C
Compilation fails.
D
j = -1 One can not specify multiple case labels with commas, as in line 4. Hence compilation error.
Correct answer: Compilation fails.
Explanation
Correct answer: Compilation fails..