9

Difference between protected and default/package access in Java

 3 years ago
source link: https://marco.dev/java-access-modifiers
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Protected vs default access control

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

Quick overview, this is a typical interview question.

protected_exp_svg.svg

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

JLS:protected

Author

Marco Molteni

Marco Molteni Blog


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK