Java Programming
Accenture Technical PrimermediumJava Programming1. Introduction To Java

Accenture Java Programming Practice Question

What will happen when the following code is compiled and run in Java 1.8? int i = 1, j = -1; switch(i) 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
j = 1
D
Compilation fails. One can not specify multiple case labels with commas, as in line 4. Hence compilation error.

Correct answer: Compilation fails. One can not specify multiple case labels with commas, as in line 4. Hence compilation error.

Explanation

Quick AnswerThe correct answer is Compilation fails. One can not specify multiple case labels with commas, as in line 4. Hence compilation error. because it directly addresses the core logic of Java Programming.

Correct answer: Compilation fails. One can not specify multiple case labels with commas, as in line 4. Hence compilation error..

Related Accenture Java Programming questions

Practice more Accenture Java Programming questions

PrimerPrep has 1400+ practice questions, 2026 simulations and coding hands-on — all free.

Watch Walkthroughs!