Skip to content
Sharp

Object-oriented programming · interview question

Why is reserve(int amount) usually safer than a generic setStock(int newStock) method?

Multiple choiceMediumchapter-3-curatedpremiumoopcontrolled-mutation
Choose one answer
Answer and explanation

Correct answer

A. Because it expresses the business action and can validate the transition properly

Why

reserve(...) tells the story of what is happening and gives the class a place to reject impossible requests. A generic setter often exposes too much mutation power without enough business context.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →