Skip to content
Sharp

Object-oriented programming · interview question

Which Java keyword would you use to restrict access to class members, ensuring encapsulation?

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

Correct answer

B. Private

Why

The 'private' keyword restricts access to the class members, ensuring they can only be accessed within the class, which is a fundamental part of encapsulation.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →