Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
Members of a class can be private, public or protected. As explained in Section , 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.