Skip to content
Sharp

Object-oriented programming · interview question

What access modifier should be used for fields to adhere to encapsulation principles?

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

Correct answer

C. Private

Why

Fields should generally be private to enforce encapsulation. This prevents external code from directly accessing or modifying the fields, allowing the class to control how its data is manipulated.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →