Virtual declares a method as a virtual method so that the derived class can override this method. Generally, the created method cannot be rewritten. For example, there is a method in Class.
Protected void method (){
Original code ....;
}
Class B is inherited from Class A. Class B can call the method () method of Class A, but cannot change the method body Code. However, when class A uses virtual declarations, this method is: protected virtual void method (), Class B can override this method by using override
Protected override void method (){
New Code ....;
}
Virtual can be used in base classes and abstract classes.
The abstract declaration method is an abstract method. The abstract method has no code body and only one method name is declared:
Protected abstract void method ();
When the abstract declaration method is used, its derived class must override this method. For example, Class B is declared in abstract class A and inherited from abstract class, override must be used to override this method in Class B.
Protected override void method (){
New Code ....;
}
Abstract can only be used in abstract classes.
Override is the keyword used by the derived class to override the parent class method (including the virtual method, abstract method, and interface method). If you want to override the method, you can use the override declaration.
Differences and usage of virtual, abstract, and override in C #