Skip to content
Sharp

Modern Java · interview question

In Java 17, what is a major benefit of using switch expressions with enums?

Multiple choiceEasychapter-12-curatedpremiummodern-javaswitch-expressions
Choose one answer
Answer and explanation

Correct answer

C. Compile-time exhaustiveness checks

Why

Switch expressions with enums benefit from compile-time exhaustiveness checks, ensuring that all enum constants are handled either explicitly or via a default case, thus preventing potential runtime errors.

Test yourself on Modern Java

A free test with instant, explained results. No account needed.

Start free test
All Modern Java questions →