What is a difference between abstract and virtual?
This question already has an answer here:
is it Virtual method have body and abstract is just a signature ????
Exactly. The point is that virtual methods can be overridden in derived classes, while abstract methods must be overridden. Likewise, a class that has at least one abstract method must itself be abstract, ie it cannot be instantiated directly since its implementation is (partially) missing.
Finally, every abstract method is also virtual by implication. virtual
basically just means that the method is dispatched at runtime to the correct class, and so it can be overridden to implement runtime polymorphism.
Abstract means you MUST override it. Virtual means you CAN override it. More or less.
I agree with both answers here, so I won't repeat them. But here's a link that might help.
10.6.3 Virtual, sealed, override, and abstract accessors
链接地址: http://www.djcxy.com/p/38114.html上一篇: 如何有一个默认的方法,但仍然能够覆盖它?
下一篇: 抽象和虚拟有什么区别?