Skip to content
Sharp

Object-oriented programming · interview question

Why would you use private access modifiers for fields in a class?

Multiple choiceMediumchapter-2-curatedpremiumoopbasic-modeling
Choose one answer
Answer and explanation

Correct answer

D. To restrict direct access and protect data integrity

Why

Using private access modifiers helps encapsulate data, ensuring that it can only be accessed or modified through controlled methods, thus maintaining data integrity.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →