In this case, is the compiler REALLY forcing me to use protected in a sealed class?

c#, inheritance

Solution

The compiler isn't really "forcing" you to use protected. It was defined as protected, and will always be protected.

Even though it is in a sealed class, it is still not like a private member. If it were private, it would not be accessible from the base class.

Problem

I can't think of an instance where a protected method should behave differently than a private method in a sealed class. And yet: ``` public abstract class Base { protected abstract void Foo(); } public sealed class Derived : Base { // Error CS0507: cannot change access modifiers when // overriding 'protected' inherited member // public override void Foo() {} // Error CS0621: virtual or abstract members cannot be private // private override void Foo() {} // Compiles just fine. protected override void Foo() {} } ```

Original source