If a virtual method is declared abstract
我的朋友问我抽象方法是否可以有虚拟修饰符。我说,不。因为抽象方法隐式地也是虚拟方法,所以它不能具有修饰符virtual。
但在阅读一篇MSDN文章时,我看到了:
...
If a virtual method is declared abstract, it is still virtual to any
class inheriting from the abstract class. A class inheriting an
abstract method cannot access the original implementation of the
method—in the previous example, DoWork on class F cannot call DoWork
on class D. In this way, an abstract class can force derived classes
to provide new method implementations for virtual methods....
我不能正确理解第一句话。你能解释一下他们想说什么吗?
谢谢。
It becomes clearer when you look at the code example directly above the quoted paragraph:
1 2 3 4 5 6 7 8 9 10 11 12 | public class D { public virtual void DoWork(int i) { // Original implementation. } } public abstract class E : D { public abstract override void DoWork(int i); } |
虚拟方法是由
当你正确的状态,抽象的方法总是虚拟的。如果你的朋友仍然不确定,这是一个官方商标:
An abstract method is implicitly a virtual method.
摘要:
ZZU1
裁决书说,必须超越