Bird
0
0

Which statement best describes the protected access modifier in Java?

easy📝 Conceptual Q11 of 15
Java - Packages and Access Control
Which statement best describes the protected access modifier in Java?
AIt allows access only within the same class.
BIt allows access only within the same package, not subclasses outside.
CIt allows access from any class anywhere.
DIt allows access within the same package and to subclasses outside the package.
Step-by-Step Solution
Solution:
  1. Step 1: Understand protected access scope

    The protected modifier allows access to members within the same package and also to subclasses even if they are in different packages.
  2. Step 2: Compare with other access levels

    Private restricts access to the same class only, public allows everywhere, and default (package-private) allows only within the same package but not subclasses outside.
  3. Final Answer:

    It allows access within the same package and to subclasses outside the package. -> Option D
  4. Quick Check:

    Protected = same package + subclasses outside [OK]
Quick Trick: Protected means package + subclass access [OK]
Common Mistakes:
  • Confusing protected with private
  • Thinking protected is public
  • Assuming protected restricts subclasses outside package

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes