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
-
Apublic
-
Babstract
-
Cprotected
-
Dsynchronized
-
Edefault 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