J.VII · Java 25 practice question

During run-time evaluation of a switch expression, when does the JVM determine which switch label applies?

Choose one answer
Check answer and explanation

Correct answer: Only after the selector expression has been evaluated and completed normally

Explanation

The JVM determines which switch label applies only after the selector expression has been evaluated and completed normally, because label matching depends on the selector's run-time value.

Common trap

Static types are checked at compile time, not used to choose a run-time label before the selector runs. Java evaluates the selector expression strictly before attempting to match any switch label, never in parallel.

Source: JLS SE 25 §15.28.2. Run-Time Evaluation of switch Expressions
Checked against the cited text on 2026-11-25.

Report an error in this question