Skip to content
Sharp

Object-oriented programming · interview question

Why might an e-commerce system's 'Order' class use private setters for its fields?

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

Correct answer

D. To enforce business rules when updating fields.

Why

Using private setters allows the class to control how and when its fields are updated, enforcing business rules and ensuring that any changes to the fields are consistent with the domain logic.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →