Skip to content
Sharp

Object-oriented programming · interview question

Which of the following is the best practice for managing access to an object's fields in Java?

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

Correct answer

C. Use private fields with public getters and setters

Why

Using private fields with public getters and setters is a common practice in Java to encapsulate data. It allows controlled access and modification of the fields, maintaining the integrity of the object.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →