Skip to content
Sharp

Modern Java · interview question

How would you explain a key advantage of using enums over strings for representing a set of predefined constants in an interview?

Multiple choiceMediumchapter-7-curatedpremiummodern-javamodern-java-design-choices
Choose one answer
Answer and explanation

Correct answer

D. Type safety and compile-time checking

Why

Enums provide type safety and ensure that only valid values are used, offering compile-time checking. Strings, on the other hand, can lead to errors as they do not provide any type constraints.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →