Skip to content
Sharp

Modern Java · interview question

When is a Java record usually a better fit than a traditional class?

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

Correct answer

D. When the type mainly carries a few related values with value semantics.

Why

Records work best for immutable-style carriers like summaries, DTOs, and small value objects. They reduce boilerplate, but the real benefit is that they communicate honest value semantics to the reader.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →