Skip to content
Sharp

Object-oriented programming · interview question

Why is encapsulation important in maintaining class invariants in Java?

Multiple choiceEasychapter-3-curatedpremiumoopinvariants-and-validation
Choose one answer
Answer and explanation

Correct answer

D. It helps in hiding the internal state of an object.

Why

Encapsulation hides the internal state of an object and allows access only through methods, which ensures that invariants are maintained.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →