A protected method can be called by any subclass within its class, but not by unreleated classes.

Declaring a method protected defines its access level. The other options for declaring visibility are private and public. If undeclared, the default access level is package.

The protectedMethod() method is a private method in the following class:

 public class MyClass {

    private void privateMethod() {
        System.out.println("I am private method");

    void packageMethod() { 
        System.out.println("I am package method");

    protected void protectedMethod() {
        System.out.println("I am protected method");

    public void publicMethod() {
        System.out.println("I am public method");