Inheritance of Protected Elements


If the keyword
protected is used in front of an extends clause, all inherited elements from the superclass become protected elements of the subclass. If an extends clause is a public element, all elements of the superclass are inherited with their original protection.






The color fields
red, green and blue that are inherited from Color become protected fields of ColoredPoint2, since the extends clause is preceded by the protected keyword. The inherited fields from Point keep their protection status since that extends clause is preceded by public.

The prefixes
protected and public are not inherited. A protected element cannot be accessed via dot notation - this is the essence of being protected. Additionally, protected elements may not be modified or redeclared in class modifications.



1 Flattening and Simulation of ColoredPoint

Flatten it:



Simulate it:





Look at a variable: