Polymorphism which is also called method/operator overloading.
Means creating more than one function which has same name but different signature .
There are two types of polymorphism overloading and overriding.
Overloading : creating different methods with same name but different signature in the SAME CLASS.
Overriding : Creating the a method which has same name and same signature as the method of Parent Class
In your example you have taken the concept of overriding.
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
A a1 = new A();
b b1 = new b();
a1.disp(); //Call From A
b1.disp(); //Call From B
a1 = new b();
a1.disp(); // Call From B with the instance of A
Console.ReadLine();
}
}
public class A
{
public virtual void disp()
{
Console.WriteLine("called from A");
}
}
public class b : A
{
public override void disp()
{
Console.WriteLine("called from B");
}
}
}
Hope you get it :)