Skip to content
Sharp

Object-oriented programming · interview question

How would you explain a common technique to avoid unrestricted setters in a Java interview?

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

Correct answer

C. Using private fields with controlled access methods

Why

By using private fields and providing controlled access methods, you can ensure that any changes to the fields go through a validation process, maintaining the object's integrity.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →