Multiple choice

What is the output of the following code?

public void select(){int a = 2;switch(a){Case 1: {System.out.println(case 1);}Case 2: {System.out.println(case 2);}Case 2: {System.out.println(case 2 repeated);}default: {System.out.println(default);}}}

  1. Prints case 1

  2. Compilation error

  3. Prints case 2 repeated

  4. Prints case 1 case 2

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Case 2 is given two times.