Skip to content
Sharp

Object-oriented programming · interview question

In a well-encapsulated Java class, how should the fields be accessed?

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

Correct answer

A. Through public getter and setter methods.

Why

Encapsulation is about hiding the internal state of an object and requiring all interaction to be performed through an object's methods. Using public getter and setter methods allows controlled access and modification of the 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 →