Skip to content
Sharp

Object-oriented programming · interview question

Why does making a class's fields private in Java change runtime behavior?

Multiple choiceEasychapter-3-curatedpremiumoopencapsulation
Choose one answer
Answer and explanation

Correct answer

D. Fields cannot be accessed directly from outside the class.

Why

Making a class's fields private prevents them from being accessed directly from outside the class. This enforces encapsulation by requiring access through methods, which can include validation logic.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →