Skip to content
Sharp

Object-oriented programming · interview question

Why doesn't every field deserve a setter?

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

Correct answer

A. Because every setter creates a write path that may bypass better domain methods

Why

A getter often just reveals information, but a setter opens a way to change state. Many fields are safer behind meaningful methods like changeQuantity(...) or reserve(...) instead of a generic write-anything path.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →