Pages

SPONSORED

What do you mean by Polymorphism?

 Polymorphism, as the name suggest represents many forms.["Poly" means many, and "morph" means form].Polymorphism allows methods to behave differenlty in different situations depending on the input/scenario.The polymorphic method methods behaves in the same consistent manner with all the communicating objects even though their implementations varies.

In polymorphism the behaviour of method is decided during run time depending on the type of input passed to the method. The process used by object-oriented programming languages to implement polymorphism is called dynamic binding.


Polymorphism Example
 Polymorphism can be implemented with inheritence. Base class must have virtual methods defined and implemented. Child Class can override these virtual methods by providing their own implementation as per requirement.During run time the complier decides the implemetation to be executed depending upon the type of the object requesting the execution. Thus calling the method of the base class causes the execution of the required child class.

Visit http://www.codeproject.com/Articles/1445/Introduction-to-inheritance-polymorphism-in-C
for more details on implementation and real time examples on Polymorphism.

Note : In C#, every type is polymorphic. This is because all types, including user-defined types is inherited from Object.

No comments:

Post a Comment