Java OCA OCP Practice Question 1768

Question

What will be the result of attempting to compile and run the following program?.

public class Main {
  public static void main(String[] args) {
    final int i = 3;
    final Integer iFour = 4;
    Integer iRef = 4;/*  ww  w .  j  ava  2  s .com*/
    switch (iRef) {
      case 1:
      case i:
      case 2 * i:
        System.out.println("I am not OK.");
      default:
        System.out.println("You are OK.");
      case iFour:
        System.out.println("It's OK.");
    }
  }
}

Select the one correct answer.

(a) The code will fail to compile because of the value of one of the case labels.
(b) The code will fail to compile because of the type of the switch expression.
(c) The code will compile correctly and will only print the following, when run:

    You are OK./*from w  w  w .j av  a 2s .com*/
    It's OK.

(d) The code will compile correctly and will only print the following, when run:

    It's OK.


(a)

Note

The value of the case label iFour is not a constant expression and, therefore, the code will not compile.




PreviousNext

Related