Java — Most restrictive access modifier that still allows class members in the same package to access each other

Difficulty: Easy

Correct Answer: default access

Explanation:

Introduction / Context:This question checks knowledge of package-private (default) access in Java.

Concept / Approach:Modifiers in Java:

  • public → visible everywhere.
  • protected → visible in same package + subclasses in other packages.
  • default (no modifier) → visible only within the same package.
  • private → visible only in same class.

Step-by-Step:

For restricting to "same package": default access is the most restrictive that still allows package sharing.

Final Answer:default access

More Questions from Declarations and Access Control

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion