Thursday, May 9, 2013

Compile time polymorphism

Hi Rajan,
Thats perfectly right. You need to *understand* the polymorphism concepts first.

Poly - many, morphism - faces.

The ability to have more than one version of the executable piece of code in the same name to invoke is called POLYMORPHISM.

view plaincopy to clipboardprint?
  1. Actually speaking the compiler would create a binding between the place of calling and the method definition.  


The ability to take a decision and thereby creating the binding is what gives you the name. 

The Compile time polymorphism comes in such a way that the compiler is able to differentiate the exact version of code to invoke during the compile time itself. Rather, the compiler *can take a decision of which exact method to invoke* during the compile time itself. 

Whereas in Runtime Polymorphism, the compiler is unable to take such a decision during compilation. Moreover, compiler-is-left-free-for-that-sake until runtime with which it can decide and invoke the appropriate version of the method.

Only when Inheritance is in picture, you can very well play around with the Polymorphism as you are given the rights to assign the child class objects to any of its parent/super class references. 

I hope this clears your doubt!

No comments:

Post a Comment