Skip to content
Sharp

Object-oriented programming · interview question

What should a method in an encapsulated class do to allow data modification?

Multiple choiceEasychapter-3-curatedpremiumoopobject-responsibility
Choose one answer
Answer and explanation

Correct answer

A. Provide a public setter method

Why

Providing a public setter method allows controlled modification of private fields. This adheres to encapsulation principles by letting the class manage how its data is changed, potentially applying validation or restrictions.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →