OCA Java SE 8 Mock Exam 2 - OCA Mock Question 24








Question

What's the output of the following code?

public class Main {
  public static void main(String args[]) {
    int num = 0;

    switch (num) {
    default:
      System.out.println("default");
    case 0:
      System.out.println("case1");
    case 10 * 2 - 20:
      System.out.println("case2");
      break;
    }
  }
}

    a  default 
       case1 
       case2 

    b  case1 
       case2 

    c  case2 

    d  Compilation error 

    e  Runtime exception 





Answer



D

Note

10*2-20 is 0, which is duplicated with another 0 in the case statement.