If a method or instance variable is modified by protected (rather than public or
private), then it can be accessed by name inside its own class definition, it can be
accessed by name inside any class derived from it, and it can also be accessed by name
in the definition of any class in the same package (even if the class in the same package
is not derived from it). However, the protected method or instance variable cannot be
accessed by name in any other classes. Thus, if an instance variable is marked protected
Child. However, in a class that is not in the same package as Parent and is not derived
from Parent, it is as if the protected instance variable were private.
private), then it can be accessed by name inside its own class definition, it can be
accessed by name inside any class derived from it, and it can also be accessed by name
in the definition of any class in the same package (even if the class in the same package
is not derived from it). However, the protected method or instance variable cannot be
accessed by name in any other classes. Thus, if an instance variable is marked protected
in the class Parent and the class Child is derived from the class Parent, then the
instance variable can be accessed by name inside any method definition in the classChild. However, in a class that is not in the same package as Parent and is not derived
from Parent, it is as if the protected instance variable were private.