Java Protected Access Modifier Example

Java Protected Access Modifier Example demonstrates how to control the visibility of a field, method, class, and constructor using a protected access modifier.

Java Protected Access Modifier

If a class or its members are declared as protected are only accessible by the classes of the same package and the subclasses present in any package. You can also say that the protected access modifier is similar to the default access modifier with one exception that it has visibility in subclasses.
Classes cannot be declared protected. This access modifier is generally used in a parent-child relationship.

Java Protected Access Modifier Example

Below diagram demonstrates the example of protected access modifier and it's visibility:


Comments