Skip to content
Sharp

Object-oriented programming · interview question

Why might it be problematic to allow direct access to an object's fields?

Multiple choiceHardchapter-2-curatedpremiumoopinstance-methods
Choose one answer
Answer and explanation

Correct answer

C. It violates encapsulation principles.

Why

Allowing direct access to an object's fields can violate encapsulation by exposing the internal representation. It can lead to unintended modifications and makes it difficult to enforce constraints or validation.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →