Virtual functions are the functions that doesn't really exists.The derived class can modify the virtual function by overriding it.Virtual functions are one of the way to achieve run time polymorphism
public class sample {
public virtual void fun(){
Console.WriteLine("base sample class \n");
}
}
public class A : sample{
public override void fun(){
Console.WriteLine("Class A \n");
}
}
public class B : sample{
public override void fun(){
Console.WriteLine("Class B \n");
}
}
class run{
public static void main(String[] args){
sample obj = new sample();
sample obj1 = new A();
sample obj2 = new B();
obj.fun();
obj1.fun();
obj2.fun();
}
}
Virtual functions are the functions that doesn't really exists.The derived class can modify the virtual function by overriding it.Virtual functions are one of the way to achieve run time polymorphism
Here it is explained clearly with example C# Virtual Method