Skip to content
Sharp

Object-oriented programming · interview question

Why should a class's internal state not be exposed via public mutable fields?

Multiple choiceHardchapter-3-curatedpremiumoopaccess-modifiers-and-visibility
Choose one answer
Answer and explanation

Correct answer

C. It breaks encapsulation and can lead to inconsistent states

Why

Exposing internal state via public mutable fields breaks encapsulation, allowing external code to modify the state directly. This can lead to inconsistent states and makes it difficult to maintain the class's invariants.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →