What is Polymorphism in OOPS?

Polymorphism is a Greek word which means many-forms. That means look same but act different. There are two types of polymorphism in .Net

  • Static Polymorphism
  • Dynamic Polymorphism

Static Polymorphism

Method overloading and Operator overloading are static polymorphisms. Method overloading is having the same method name with different types of parameters or different order of parameters. Method overloading cannot be done by changing only the return type.

public int Add(int a, int b)
{
     a++; // Operator overloading
     Return a+b;
}
// Method overloading. Same method name with different parameters
Public string Add(string a, string b)
{
    Return a+b;
}

It is also called Early Binding. Because call to these functions are decided at compile time itself.

Dynamic Polymorphism

Overriding a virtual method is an example for dynamic polymorphism. It is also known as Late Binding. Because calls to these functions will be decided at runtime only.

public class Animal
{
    Public virtual void Eat()
    {
        //eat by mouth
    }
}
Public class Human
{
    Public override void Eat()
    {
        //Human put food into mouth by hand
        //eat by mouth(by calling base method)
    }
}

Here both method signature are same, so the compiler won’t be knowing which method to be called, it will be decided on runtime.

Leave a Reply