Skip to content
Sharp

Object-oriented programming · interview question

Why might a Java class have private fields and public methods?

Multiple choiceMediumchapter-2-curatedpremiumoopfields-and-state
Choose one answer
Answer and explanation

Correct answer

C. To allow controlled access to the fields while hiding the implementation details

Why

Private fields with public methods support encapsulation by hiding the internal representation of the class, while providing a controlled way to access and modify the data through public methods.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →