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

Java Programming Declarations and Access Control Difficulty: Easy
Choose an option
  • A
    public
  • B
    abstract
  • C
    protected
  • D
    synchronized
  • E
    default access

Answer

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

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