Virtual method: it is a method modified with the virtual keyword and implemented in one or more Derived classes. If a method is virtual, it cannot be modified by static, abstract, or override.
Abstract method: it is a method modified by the abstract keyword. abstract methods can be considered as virtual methods without entity implementation and must be overwritten in the derived class. If a class includes abstract methods, this class is an abstract class.
(1) Virtual Methods
1. Virtual methods must contain implementations. Abstract METHODS cannot contain implementations;
2. Virtual can be overwritten by the quilt class, while abstract must be overwritten by the quilt class;
Class base
{
Public Virtual void myfunc (string SDD)
{
String STR = "DD" + SDD;
}
}
Class derived: Base
{
Public override void myfunc (string SS)
{
String STR = "DDS" + SS;
}
}
(2) Abstract METHODS
1. If the class members are modified in abstract, abstract must be added before the class, because only abstract classes can have abstract methods.
Abstract class base
{
Public abstract void myfunc (string SDD)
{
String STR = "DD" + SDD; // error. The subject cannot be declared because it is marked as abstract
}
}
2. Abstract must be overwritten by the quilt class
Abstract class base
{
Public abstract void myfunc ();
}
Class derived: Base
{
Public override void myfunc ()
{
}
}