Skip to content
Sharp

Object-oriented programming · interview question

Why should setter methods be avoided in an immutable class?

Multiple choiceMediumchapter-3-curatedpremiumoopimmutability-basics
Choose one answer
Answer and explanation

Correct answer

B. They allow modification of the object's state.

Why

Setter methods allow modification of an object's state, which contradicts the principles of immutability. An immutable class should not allow any changes to its state after construction.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →