Skip to content
Sharp

Object-oriented programming · interview question

In terms of encapsulation, why is it important for a class to control the visibility of its fields?

Multiple choiceEasychapter-3-curatedpremiumoopgetters-and-setters-design
Choose one answer
Answer and explanation

Correct answer

D. To protect the integrity of the data.

Why

Controlling field visibility is crucial for protecting the data integrity by restricting direct access and allowing data to be modified only through controlled methods, ensuring proper validation and business rules are applied.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →