O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Access Modifiers and Inheritance

The private and the protected access modifiers are especially important in connection with inheritance. This section looks closer at these modifiers, along with the ability to declare a class member protected, internal, or internal protected.

The protected Access Modifier

As mentioned in the analysis of Listing 16.3, a protected class member can be accessed only from within its own class (like a private member) and from its subclasses. You should avoid declaring data members to be protected because it breaks with the encapsulation principles discussed in Chapter 3, “A Guided Tour Through C#: Part I.” The next section looks more closely at this issue.

Accessing private Base Class Members

The Car class presented ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required