Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Derivation and Access Control

 

Members of a class can be private, public or protected. As explained in Section gif, private members are accessible only by methods of the class in which the member is declared. In particular, this means that the methods of a derived class cannot access the private members of the base classes even though the derived class has inherited those members! On the other hand, if we make the members of the base class public, then all classes can access those members directly, not just derived classes.

Java provides a third category of access control--protected. Protected members can be used by methods of the class in which the member is declared as well as by methods of all the classes derived from the class in which the member is declared.


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.