Multiple choice technology platforms and products

Which access modifier is more restrictive ?

  1. public is more restrictive than protected

  2. package (default access modifier) is more restrictive that private

  3. package is more restrictive that public

  4. package is more restrictive that protected

  5. protected is more restrictive that package

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In Java, access modifiers restrict visibility in this order from most to least restrictive: private (only same class), package/default (same package), protected (same package + subclasses), public (everywhere). Since package-level access allows access only within the same package while protected additionally allows subclasses outside the package to access the member, package is indeed more restrictive than protected.

AI explanation

Java access levels from most to least restrictive are: private, default (package-private), protected, public. protected grants package access PLUS access to subclasses in other packages, so it is less restrictive than the package/default level. Therefore package (default) is more restrictive than protected, making the marked statement true.