Java access modifiers

Just a reminder:

  • package protected – Scope that indicates that an instance variable is visible to other classes within its same package, or to subclasses of the class containing the instance variable. This scope is the default scope in Java, and is indicated by no scope indicator.
  • private – Scope indicator that hides an instance variable from all other classes, regardless of their package or their class hierarchy relationship to the class containing the variable.
  • protected – Scope indicator that makes an instance variable visible to subclasses that inherit from the class containing the instance variable.
  • public – Scope indicator that makes an instance variable visible to any class, regardless of package or class hierarchy relationship to the class containing the instance variable.

2 Responses to “Java access modifiers”

  1. Phil Says:

    So, I was recently asked about this… And protected is also visible to classes in the same package. This is new to me… When did it change?

  2. tadekp Says:

    Hum… I checked in the JavaLanguage specification here and it seems that you’re right. I checked in the first version of JLS and it has always been there.

    Tnx for finding a bug in my blog entry ;-)

    Tadek

Leave a Reply