What is the protected modifier for?
The Java visibility modifiers are concerned with data hiding and encapsulation, they control which classes and sub-classes can read and write variable values and call methods. The protected visibility modifier means that the field or method is accessible from within the host class itself, and internally to other classes in the same package and subclasses that may be in a different package. Protected fields cannot be accessed through the public API of a class. The protected modifier is usually used to develop the features of an inheritance hierarchy by sharing access to common variables and methods with subclasses. It offers greater scope for extension than package visibility without creating a public API. Actions: Follow-up, clarify or correct this answer. Submit a new question.