Skip to content
Sharp

Object-oriented programming · interview question

Why do teams use private fields in a Java class in production code?

Multiple choiceMediumchapter-3-curatedpremiumoopimmutability-basics
Choose one answer
Answer and explanation

Correct answer

B. It restricts access to the fields from outside the class.

Why

Private fields restrict access from outside the class, enforcing encapsulation. This allows the class to control how its fields are accessed and modified.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →