为什么我可以密封一个实现接口但不能封闭成员的类?

Sim*_*mon 2 .net virtual inheritance interface sealed

鉴于此接口

public interface IMyInterface
{
    string Method1();
}
Run Code Online (Sandbox Code Playgroud)

为什么这是有效的

public sealed class InheretedFromInterfaceSealed: IMyInterface
{
    public string Method1()
    {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

但这不是

public class InheretedFromInterfaceWithSomeSealed: IMyInterface
{
    public sealed string Method1()
    {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

然而,它是抽象类的有效场景

public abstract class AbstractClass
{
    public abstract string Method1();
}
public class InheretedFromAbstractWithSomeSealed: AbstractClass
{
    public sealed override string Method1()
    {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

Meh*_*dad 6

因为默认情况下每个方法都是密封的,除非它是虚拟的,或者除非你没有说明sealed已经虚拟的东西并且你正在覆盖.