抽象方法重写抽象方法 [英] 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屋!
查看全文