C # virtual methods and abstract methods

virtual: Virtual, essentially.

abstrct: abstract, abstract.

1. The virtual method must have an implementation part, and the abstract method cannot have an implementation part;
2. The virtual method can be rewritten in the derived class or not. The abstract method must be rewritten in the derived class
3. The virtual method can be in Declared in any non-sealed class, abstract methods can only be declared in the abstract class.
4. If the class contains abstract methods, then the class must also be abstract and cannot be instantiated.

In contrast, virtual methods tend to reuse code, and abstract methods are more like a convention to constrain subclasses to implement a method.

Guess you like

Origin www.cnblogs.com/zhengxia/p/12672990.html