5.4. Methods and Inheritance

We mentioned earlier that you can control inheritance in C# by using various access modifiers on the class members. This section explores the C# access modifiers.

5.4.1. Access Modifiers

In Java, a subclass cannot override a superclass method and make its access level more restrictive. That is, a public superclass method cannot be made private or protected, and a protected superclass method cannot be made private in the subclass. Subclasses can, however, make the methods less restrictive. C# does not have this restriction; in fact, a subclass can make a method less or more restrictive than the superclass, as long as the method can be called on the reference to which the created object is assigned. In Listing 5.11 ...

Get .NET for Java Developers: Migrating to C# 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.