Which access modifier allows access in the same package and subclasses?

Get ready for your Object‑Oriented Programming Test. Use flashcards and multiple-choice questions. Each question includes hints and explanations. Prepare for your exam today!

Multiple Choice

Which access modifier allows access in the same package and subclasses?

Explanation:
Protected access lets a member be visible inside its own package and also to any subclass, even if that subclass is in a different package. This combination makes it the right choice when you want derived classes to reuse or extend behavior while still keeping access restricted from the general public API. Private would limit access to the defining class only, public would expose it everywhere, and default (no modifier) allows access only within the same package (not to subclasses in other packages), which doesn't meet the requirement of subclass access across packages.

Protected access lets a member be visible inside its own package and also to any subclass, even if that subclass is in a different package. This combination makes it the right choice when you want derived classes to reuse or extend behavior while still keeping access restricted from the general public API. Private would limit access to the defining class only, public would expose it everywhere, and default (no modifier) allows access only within the same package (not to subclasses in other packages), which doesn't meet the requirement of subclass access across packages.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy