Java - What is the output: duplicate case value

Question

What is the output:

public class Main {
  public static void main(String[] args) {
    int num = 10;
    switch (num) {
    case 10:
      num++;
    case 10:
      num--;
    default:
      num = 100;
    }

    System.out.println(num);
  }
}


Click to view the answer

case 10: // A compile-time error. Duplicate case label 10

Note

Two case labels in a switch statement cannot be the same.

The code would not compile because case label 10 is repeated.

Related Quiz