What is the significance of the keyword virtual in the method definition?
- The method with virtual keyword signifies that it can be overridden.
- Virtual keyword is a member function of a class.
- It is used in the base class method.
Example://base class
public virtual A()
{
int a,b;
int c = a + b;
Console.WriteLine(c);
}
//derived class
public override A()
{
int a,b
int c = a * b;
Console.WriteLine(c);
}
- Virtual keyword is used to modify a method, property, indexer or event declaration.
- The implementation of a virtual member can be changed by an overriding member in a derived class.