Skip to content
Sharp

Modern Java · interview question

How do records in Java help in achieving immutability?

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

Correct answer

D. By automatically generating accessor methods without setters.

Why

Records automatically generate accessor methods without setters, ensuring that the fields remain immutable after the object is created.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →