Protected Accessibility

So far, we’ve 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:

In this example, the Count property ...

Get C# 4.0 Unleashed 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.