Data Structures and Algorithms with Object-Oriented Design Patterns in C#
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.

This is where protected access control comes in. 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 © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.