Skip to content
Sharp

Object-oriented programming · interview question

In Java, why should field variables typically be private?

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

Correct answer

C. To restrict direct access and protect object integrity

Why

Fields are generally private to enforce encapsulation, ensuring that the internal state of an object can only be modified through controlled methods, maintaining object integrity.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →