Skip to content
Sharp

Object-oriented programming · interview question

Why might you choose to implement a domain-specific method instead of a generic setter for updating a field?

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

Correct answer

C. To enforce specific business rules.

Why

A domain-specific method can enforce business rules and validation logic, ensuring that any changes to a field comply with the application's requirements, which a generic setter may not enforce.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →