Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is the protected modifier for?

modifier protected
0
Posted

What is the protected modifier for?

0

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123