Tuesday, September 10, 2013

What is Polymorphism ? What is Static and Dynamic Polymorphism in .Net ?


Polymorphism means having more than one form.

Polymorphism means same operation may behave differently on different classes.

Polymorphism is classified into compile time polymorphism or early binding or static binding and Runtime polymorphism or late binding or dynamic binding.

1) Static/early Binding: 
The mechanism of linking function with an object during compile time is called as static or early binding.

Ex: Method overloading and operator overloading.
Method\function Overloading:

Two or more functions having save name, but they are differ in thier function signature is called as Method\function overloading.

Function signature means: They can differ in Number of parameters, sequence of parameter & data type of parameter.

Method Overloading forms compile-time polymorphism.

Method Overloading


=> Advantages of method Overloading in C#.Net / When to Use Method Overloading / Why To Use Method Overloading


2) Dynamic/Late Binding:
The mechanism of linking function with an object during run time is called as dynamic or late binding.

Ex: Method overriding / virtual functions / abstract classes

Method Overriding:

Method overriding occures when child class delcares a method with same name & signature as parent class.

Here parent class must declares the method with virtual or overridable keyword, and child class must uses override keyword.

Please look example as below,



3 comments:

  1. Sir, when we override a method with different operations which method call first?
    and what is the advantage of Overriding?

    ReplyDelete
    Replies
    1. Hi,

      For advantage/when to use/ why to use overriding please check below link,

      http://dotnetpeoples.blogspot.in/2016/03/when-to-use-method-overriding-method.html

      http://dotnetpeoples.blogspot.in/2016/03/method-overriding-vs-method-hiding.html

      "when we override a method with different operations which method call first?" Means ??

      Delete
    2. Hi User,

      Please check below link, I have updated advantages of it,

      https://dotnetpeoples.blogspot.in/2016/04/whenwhy-to-use-method-overloading.html

      Regards,
      Jatin

      Delete