blog

Home / DeveloperSection / Blogs / Polymorphism

Polymorphism

Amit Singh4776 07-Oct-2010

When a message can be processed in different ways is called polymorphism. Polymorphism means many forms.  Polymorphism is one of the fundamental concepts of OOP.

Polymorphism provides following features:
·   It allows you to invoke method of derived class through base class
reference during runtime.
·   It has the ability for classes to provide different implementations of
methods that are through the same name.
Polymorphism is of two types:

(1)    Compile Time polymorphism /Overloading

(2)    Runtime Polymorphism/ Overriding

Compile Time polymorphism:

Compile Time polymorphism is method and operators overloading. It is also called early binding.

In method overloading method performs the different task at the different input parameters.

Compile Time polymorphism:

Compile Time polymorphism is done using inheritance and virtual functions. Method overriding is called runtime polymorphism. It is also called binding.

When overriding a method, you can change the behavior of the method for the derived class. Overloading a method simply involves having another method with same prototype.

Example:
Public class print
{
Public void display(string name)
{
Console.WriteLine(“Your name is :” +name);
}
Public void display(int age, flot markes)
{
Console.WriteLine(“Your age is :” +age);
Console.WriteLine(“Your mark is :” +marks);
 
}
}
Static void main()
{
Print  obj=new print();
Obj.display(“Mind Stick”);
Obj.display(25,76.50f);
Console.ReadLine();
}
}
}

 You can also read these related post

 https://www.mindstick.com/blog/506/polymorphism-in-c-sharp

https://www.mindstick.com/Articles/32/polymorphism

https://www.mindstick.com/interview/81/what-is-meant-by-polymorphism


Updated 18-Sep-2014

Leave Comment

Comments

Liked By