Skip to content
Sharp

Object-oriented programming · interview question

Why do teams use the 'private' access modifier in a class in production code?

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

Correct answer

C. To restrict access to class members

Why

The 'private' access modifier is used to restrict access to class members. It supports encapsulation by ensuring that the internal state of an object is not directly accessible from outside the class.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →