Skip to content
Sharp

Object-oriented programming · interview question

How would you explain the real benefit of hiding fields behind meaningful methods in an interview?

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

Correct answer

B. The class can validate and control state changes instead of accepting raw assignments

Why

Methods such as reserve(...) or restock(...) make the business action explicit and give the class a place to reject invalid changes. That is much stronger than exposing raw writable fields.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →