Skip to content
Sharp

Object-oriented programming · interview question

Why do teams use encapsulation in Java in production code?

Multiple choiceMediumchapter-3-curatedpremiumoopcontrolled-mutation
Choose one answer
Answer and explanation

Correct answer

C. It helps in maintaining state consistency and security.

Why

Encapsulation allows a class to maintain control over its state by restricting direct access to its fields and providing controlled pathways for state changes, ensuring consistency and security.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →