Protected Accessibility

So far, we’ve mostly dealt with publicly accessible members during our explanation of inheritance. However, a more granular accessibility level, called protected, exists for use in combination with inheritance and OOP.

Whereas public members are visible to the world, both inside and outside the assembly, private members are visible only within the declaring type (including nested types). Because type hierarchies establish “families of types,” a corresponding accessibility level seems attractive. This is what protected does: It allows access to the member to code in the declaring type as well as code in derived types. You’ve seen such an example with our introductory Counter exploration:

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.