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.
Detailed Solution & Conceptual Analysis
This question has been retained as-is due to its unique context.
Key Engineering Takeaway
In Java Programming, understanding the underlying mechanics of Java Programming is critical for writing performant, bug-free production code and passing rigorous technical architecture reviews.