Difference between protected and default/package access in Java

Protected vs default access control

Differences between the protected and the default/package-private access.

Quick overview, this is a typical interview question.

In short:

  • the protected access has a modifier (keyword): protected
  • the default access doesn't have any modifier.
  • the default access doesn't allow access outside of the package

The complete details (Java Language Specification 11)

JLS: Access Control


WebApp built by Marco using SpringBoot, Java 17, Mustache, Markdown and in Azure