抽象方法覆盖抽象方法 [英] An abstract method overrides an abstract method
本文介绍了抽象方法覆盖抽象方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public abstract class A
{
public abstract void Process();
}
public abstract class B : A
{
public abstract override void Process();
}
public class C : B
{
public override void Process()
{
Console.WriteLine("abc");
}
}
此代码引发编译错误:'B' 未实现继承的抽象成员 'A.Process()'.
This code throws an Compilation Error: 'B' does not implement inherited abstract member 'A.Process()'.
有没有办法做到这一点?
Is there any way to do this?
推荐答案
只需在类 B 中完全省略该方法.B 无论如何从 A 继承它,并且由于 B 本身是抽象的,因此您不需要明确地再次实现它.
Just leave out the method completely in class B. B inherits it anyway from A, and since B itself is abstract, you do not explicitly need to implement it again.
这篇关于抽象方法覆盖抽象方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文