Skip to content
Sharp

Object-oriented programming · interview question

How would you explain a potential issue when a class exposes its fields as public in an interview?

Multiple choiceEasychapter-3-curatedpremiumoopobject-responsibility
Choose one answer
Answer and explanation

Correct answer

C. Fields can be modified without validation

Why

Exposing fields as public allows them to be modified without any validation, potentially leading to inconsistent or invalid states. Encapsulation protects fields from such direct access.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →