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

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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?