Polymorphism means having same name and many forms. Polymorphism is of two types static and dynamic.
Static polymorphism
When the linking between method/functions and objects is done in compile time, it is called static binding.
In C# static polymorphism can be achieved in two ways,
- Function Overloading
- Operator Overloading
Function Overloading
In function overloading two or method/functions have same name but can have different definitions or they may have different parameters.
using System;
class Polymorphism{
public void show(int a=10)
{
Console.WriteLine("The value of variable is: ", a);
}
public void show()
{
Console.WriteLine("This is an example of Function Overloading.");
}
public void show(string s = 'Hello')
{
Console.WriteLine("Greeting from this method ", s);
}
}