这是我的课,我不希望这个方法在子类中被覆盖,我该如何完成这个行为?
class A { public virtual void demo() { } } class B : A { public override void demo() { } } // when Class B be inherited in C,methods can be overridden further,// but I don't want the method to be overridden further. class C : B { }
解决方法
put’sealed’修饰符覆盖void demo()
class A { public virtual void demo() { } } class B:A { public sealed override void demo() { } } //B can be inherited in C but demo() method can not be overriden further class C:B { }