In C # learning, it is easy to confuse the use of virtual and abstract methods. Now let's discuss the differences between them. Both of them involve the use of override in a derived class.
1. Virtual Method)
Virtual keywords are used to modify methods in the base class. Virtual instances can be used in two scenarios:
Case 1: The virtual method is defined in the base class, but the virtual method is not overwritten in the derived class. In the call to a derived class instance, the virtual method uses the method defined by the base class.
Case 2: The virtual method is defined in the base class, and then override is used in the derived class to override the method. In the call to a derived class instance, this virtual method uses a derived override method.
Ii. Abstract Method)
Abstract keywords can only be used to modify methods in abstract classes without specific implementation. Abstract methods must be implemented using the override keyword in the derived class.