QuestionQ60

Controlling Program Flow

Given this code fragment:

Question Image

What is the outcome?

  • A The code fails to compile.
  • B 7
  • C 8
  • D 5
Explanation

A Java switch expression must be exhaustive. These labels cover only the integer values 1 through 6; because there is no default label to handle all other int values, the code produces a compile-time error.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!