Difference Between Virtual And Abstract Method in C#
|It can be declared inside abstract as well as non abstract class.
||It can be declared only inside abstract class.
|Virtual method can have a method body.
||Abstract methods have only the signature. It cannot have method body.
|It may be overridden.
||It must be overridden.
|Class containing virtual method can be instantiated.
||Class containing abstract method cannot be instantiated. It can only be inherited.
|If you feel that the derived class may or may not override the base class method, then you will define the base class method as virtual.
||If you want to enforce that derived class must override the base class method then you will define the base class method as abstract.
C# - Frequently Asked Interview Questions