Skip to content
Sharp

Object-oriented programming · interview question

How does the concept of immutability relate to encapsulation in Java?

Multiple choiceMediumchapter-3-curatedpremiumoopgetters-and-setters-design
Choose one answer
Answer and explanation

Correct answer

D. Immutable objects enhance encapsulation by preventing state changes.

Why

Immutability prevents changes to an object's state after it's constructed, which complements encapsulation by safeguarding the internal state against unintended modifications.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →