Introduction
According to MSDN:
Polymorphism is often referred to as the third pillar of object-oriented programming, after encapsulation and inheritance. Polymorphism is a Greek word that means "many-shaped".
In simple terms, in Polymorphism an object can take make forms.
Note: To understand polymorphism, make sure you have understood the concepts of Inheritance. As we know that the Polymorphism can’t achieved without Inheritance.
Description:
Polymorphism can be achived in two ways, That is:
- Static Polymorphism or Compile time Polymorphism
Compile time polymorphism is nothing but the method overloading in C#. In simple terms we can say that a class can have more than one method with same name but with different number of arguments or different types of arguments or both.
Compile time polymorphism can be archived in Single Class.
Constructor can be overloaded.
Example- namespace Polymorphism
- {
- class MyClass
- {
- public void show()
- {
- MessageBox.Show("This is 'Show' Without Argumant ");
- }
- public void show(int num1, string str1)
- {
- MessageBox.Show("This is 'Show' With 2 Argumant ");
- }
- public void show(string str1, int num1)
- {
- MessageBox.Show("This is 'Show' With 2 Argumant Difference in Sequence of Paramanters");
- }
- public void show(string str1, string str2)
- {
- MessageBox.Show("This is 'Show' With 2 Argumant but Different in Type ");
- }
- public void show(string str1, string str2, string str3)
- {
- MessageBox.Show("This is 'Show' With 3 Argumant Difference in Number of Paramanters");
- }
- }
- class AnotherClass
- {
- public void Display()
- {
- //we have Called all the Oveloaded Methods by using single instance of the class.
- MyClass obj = new MyClass();
- obj.show();
- obj.show(1, "test");
- obj.show("text", 5);
- obj.show("AAA", "BBB", "CCC");
- obj.show("AAA", "XXX");
- }
- }
- }
- Dynamic Polymorphism or Runtime Polymorphism
Child class has the same method as of base class.
Dynamic Polymorphism can be archived using method overriding. Overriding means a derived class is implementing a method of its super class.
Example- namespace Polymorphism
- {
- class ParentClass
- {
- //Add virtual keyword to make sure that this methord will be override in child class.
- public virtual void show()
- {
- MessageBox.Show("");
- }
- public virtual void Display()
- {
- MessageBox.Show("");
- }
- //this is not a virtual method , and it can't be override
- public void Disp()
- {
- MessageBox.Show("");
- }
- }
- class ChildClass: ParentClass
- {
- //we have override the method in Child class which is marked as virtual.
- public override void show()
- {
- MessageBox.Show("");
- }
- //we have override the method in Child class which is marked as virtual.
- public override void Display()
- {
- MessageBox.Show("");
- }
- }
- }
Important points
Polymorphism provides the functionality to Call Child class methods using instance of Parent class that is not there in Inheritance.
The “new” keyword is used to hide the method of parent or base class which we don’t own. This is called method hiding.

Kundan JhaPosted Oct 28, 2015, 9:13 AM
thank you .........All
Nilesh JadavPosted Oct 27, 2015, 3:02 AM
Great Article sir !
Humayun Kabir MamunPosted Oct 27, 2015, 12:23 AM
Nice...
Debendra DashPosted Oct 26, 2015, 3:14 PM
good one.
Gowtham KPosted Oct 26, 2015, 11:12 AM
Thanks for sharing
Priyaranjan K SPosted Oct 26, 2015, 8:24 AM
Thanks for the share .
Mukesh KumarPosted Oct 26, 2015, 8:16 AM
Great Work
Harshad PansuriyaPosted Oct 26, 2015, 7:46 AM
nice one