virtual keyword is used in the base class method when derived class use virtual method we use override key with derived class method and the implementation of method can be changed but not affecting the type signature of base class.
eg: base class public virtual method1() { int a,b,c; c=a+b; Console.WriteLine(c); }
derived class
public override method1() { int a,b,c; c=a*b; Console.WriteLine(c); }
virtual meathod is define in base class and which is over-ridden in child class.. base:class public virtual method1() { string c="virtual method1" Console.WriteLine(c); }
derived class
public override method1() { string c="override meathod" Console.WriteLine(c); }
Basically virtual method has drastical affect on performance of application. No Doubt we can do all the things without virtual function but if we use Virtual then we have following benefits.
1. Same of name of function can be used in derived class after overriding and can change its body there but with same signature
2. Overrided function will point to same memory location that is of the virtual function. means same memory location can be shared.