protected Java Keyword with Examples

The protected keyword is an access control modifier that may be applied to a class, a method or a field (a variable declared in a class).
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 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.
protected Java Keyword Example
Below diagram demonstrates the example of protected access modifier and it’s visibility: