What is the difference between abstract and virtual?

both abstract and virtual will be redefined in the child class than the difference.

this is a virtual method that has a body, and abstract is just a signature ????

+6
c #
source share
3 answers

this is a virtual method that has a body, and abstract is just a signature ????

That's right. The fact is that virtual methods can be redefined in derived classes, and abstract methods must be redefined. Similarly, a class that has at least one abstract method must itself be abstract, i.e. It cannot be created directly, since its implementation is (partially) absent.

Finally, each abstract method is also virtual in meaning. virtual basically means that the method is dispatched at runtime to the correct class and therefore can be overridden to implement polymorphism at runtime.

+24
source share

Abstract means you MUST override it. Virtual means that you can override it. More or less.

+17
source share

I agree with both answers here, so I will not repeat them. But here is a link that might help.

10.6.3 Virtual, Closed, Overridden, and Abstract Accessors

+1
source share

All Articles