Skip to content
Sharp

Modern Java · interview question

In the context of designing an e-commerce application, which of the following is a key advantage of using an enum to represent order statuses over a string?

Multiple choiceMediumchapter-7-curatedpremiummodern-javaenums
Choose one answer
Answer and explanation

Correct answer

A. Enums provide compile-time type safety, reducing the chance of invalid values.

Why

Enums provide compile-time type safety, ensuring that only valid order statuses are used. This reduces bugs related to invalid or misspelled status names, which can occur when using strings. With enums, invalid states are caught at compile time rather than runtime.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →