Skip to content
Sharp

Object-oriented programming · interview question

Why do teams use encapsulation in Java in production code?

Multiple choiceEasychapter-3-curatedpremiumoopdefensive-copying
Choose one answer
Answer and explanation

Correct answer

D. To protect object state from unintended modification

Why

Encapsulation is a core principle of OOP that involves restricting access to the internal state of an object. This is done to protect the object's data from unintended or harmful modifications.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →