Java Language Visibility (controlling access to members of a class) Summary of Class Member Access Modifiers

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

Access ModifierVisibilityInheritance
PrivateClass onlyCan't be inherited
No modifier / PackageIn packageAvailable if subclass in package
ProtectedIn packageAvailable in subclass
PublicEverywhereAvailable in subclass

There was once a private protected (both keywords at once) modifier that could be applied to methods or variables to make them accessible from a subclass outside the package, but make them private to the classes in that package. However, this was removed in Java 1.0's release.



Got any Java Language Question?