9.3 protected
Members
Chapter 8 discussed access modifiers public
and private
. A class’s public
members are accessible wherever the program has a reference to an object of that class or one of its subclasses. A class’s private
members are accessible only within the class itself. In this section, we introduce the access modifier protected
. Using protected
access offers an intermediate level of access between public
and private
. A superclass’s protected
members can be accessed by members of that superclass, by members of its subclasses and by members of other classes in the same package—protected
members also have package access.
All public
and protected
superclass members retain their original access modifier when they become members of the subclass— ...
Get Java How to Program, Early Objects, 11th Edition 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.