Skip to content
Sharp

Modern Java · interview question

How do records in Java help in maintaining the immutability of objects?

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

Correct answer

C. By ensuring fields are final and cannot be modified after construction.

Why

Records in Java ensure immutability by making all fields final, meaning they are set once at construction and cannot be changed thereafter. This reinforces the concept of immutable data holders.

Test yourself on Modern Java

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

Start free test
All Modern Java questions →