Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static polymorphism v/s dynamic polymorphism

 
Vinny Menon
Ranch Hand
Posts: 62
Java Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
method overloading would be an example of static polymorphism
whereas overriding would be an example of dynamic polymorphism.

B'Coz,in case of overloading,at compile time the compiler knows which method to link to the call .
However,it is determined at runtime for dynamic polymorphism.

Please comment if i am correct on this one.
Thanks for your replies.
-vinny m
 
sarika mishra
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U are absolutely correct..

Dynamic, or late, binding occurs when a method is defined for several classes in a family, but the actual code for the method is not attached, or bound, until execution time.This gives support for overriding...

Static binding occurs when a method is defined with the same name but with different headers and implementations. The actual code for the method is attached, or bound, at compile time. Static binding is used to support overloaded methods in Java.
 
badri nath
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vinny
What you say is correct and this has been discussed many times in this forum.Which method to be called is decided at runtime only but not at compile time.At compile time it just checks whether syntax is correct or not but does not perform any operations more than that.Dont know why people have termed both as static(overloading) and dynamic(overriding) which is not even clear to me.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic