Skip to content
Sharp

Core Java · interview question

Which Java keyword restricts access to variables and methods to the containing class only?

Multiple choiceEasychapter-3-curatedpremiumcore-javacode-reading-and-state-safety
Choose one answer
Answer and explanation

Correct answer

D. Private

Why

The 'private' keyword ensures that variables and methods are not accessible outside the containing class, making it ideal for encapsulation.

Test yourself on Core Java

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

Start free test
All Core Java questions →