Tuesday, November 17, 2009

Runtime polymorphism vs Compile time polymorphism

 Polymorphism can be achieved in 3 ways:

  1. Method overloading     (compile time polymorphism
  2. Method overriding through inheritance (runtime polymorphism)
  3. Method overriding through C# interface (runtime polymorphism)
Runtime polymorphism means, compiler would come to know which method to execute, at runtime not compile time. We can implement the runtime polymorphism by using override keyword.

Late binding
  • The decision as to which version of method to invoke cannot be made at compile time.
  • It has to be done at run-time.
  • This is reffered as late binding


Reference:

http://www.dickbaldwin.com/csharp/Cs000120.htm


Difference between compile time & run time polymorphism:

  • override functions have same signatures, but implemented in different classes
  • overload is function with same name but different signatures in same class


No comments: