# protected Java Keyword

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).

## Examples

      public class MyPublicClass
      {
         protected class MyPrivateClass
         {
         }

         protected int i;

         protected String myMethod()
         {
           <statements>
         }
      }

## Remarks

- A protected class, method or field may be referenced from within the class in which it is declared, any other classes in the same package, and any subclasses regardless of the package in which a subclass is declared.

- The default access for all class members is package access, meaning that unless a specific access control modifier is present the class members are accessible from within any class in the same package.

Related Topics

private Java Keyword

public Java Keyword