Skip to content
Sharp

Object-oriented programming · interview question

Why is it generally a good practice to make fields private in a Java class?

Multiple choiceEasychapter-3-curatedpremiumoopgetters-and-setters-design
Choose one answer
Answer and explanation

Correct answer

D. To prevent unauthorized access and modification.

Why

Making fields private ensures control over their access and modification through well-defined methods, protecting the internal state of the object from external interference.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →