protected Keyword

Using a protected keyword declares protected visibility for a class, variable, or method. Items with protected visibility can be accessed by any subclasses of the class in which the protected item is declared, but cannot be accessed from other classes in the program.

Here’s an example that declares a protected class variable:

protected int Diameter;

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.