Skip to content
Sharp

Object-oriented programming · interview question

Which Java keyword would you use to allow a subclass in a different package to access a superclass's member?

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

Correct answer

A. Protected

Why

The 'protected' access modifier allows a subclass in a different package to access a superclass's member. It enables inheritance while maintaining a level 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 →