Skip to content
Sharp

Object-oriented programming · interview question

Why can using public fields in a class become a problem in practice?

Multiple choiceMediumchapter-3-curatedpremiumoopaccess-modifiers-and-visibility
Choose one answer
Answer and explanation

Correct answer

A. Reduced encapsulation and potential for data corruption.

Why

Public fields allow external code to modify the class's internal state directly, reducing encapsulation and increasing the risk of data corruption. It's better to use private fields with controlled access methods.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →