Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is overloading example of static or dynamic polymorphism

 
Ramesh Chandra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i would like to know whether method/operator overloading comes under static polymorphism or dynamic polymorphism....

i request you a detail explanation

thnx......
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what reason do you want to know? Is there some example code you have questions about?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The term "static polymorphism" has been used to refer to overloading. "static" here means that the decision about which method to call is made when the program is compiled. This is in contrast to "dynamic polymorphism", what you get from overriding methods in Java, in which that decision is deferred until runtime.

But some people -- myself included -- dislike this term "static polymorphism," and prefer to use "polymorphism," without qualification, to mean runtime binding of method calls. The term "overloaded methods" is just fine for overloaded methods, which aren't, IMO, an object-oriented concept.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But then if you override an overloaded method ...
 
Jon Lee
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
polymorphism and overloading are different concepts, not comparable...
 
Ramesh Chandra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friedman,
Thnx for posting me a detailed solution but i have one doubt regarding overloading in the enduser perspective...

generally our understanding is that in overloading , which method is to be called is decided during compile time... but we are passing the values to these overloaded methods during runtime. depending on the values that we give at runtime the proper method will be invoked...

this sounds like dynamic polymorphism as the method to be invoked is decided during the runtime depending upon the values we pass.

hope u understood my probs
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Friedman!
There is nothing like early binding in java as each method get bind (or get call) at run-time only. In byte (class) file there is'nt any link for any method.

Make me correct if am wrong!

With Best Regards!
Sachin Dimble.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some points from my side. Please let me know how many are correct:

1] Java doesn't provide user defined operator overloading.

2] Overloading is not an example of polymorphism. It is as good as defining new method, just using the same name.

3] Overridding is the example of polymorphism. Here all games happen. Compiler think something else and JVM execute something else.


[ December 09, 2005: Message edited by: rathi ji ]
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi rathi Ji!
According to me..
1] correct
2] Not ok overloading is the kind of polymorphism
3] correct,overriding is also kind of polymorphism.

With Best Regards!
Sachin Dimble.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sachin Dimble:

2] Not ok overloading is the kind of polymorphism


I disagree. Overloading is nothing more than a fa�on de parler.
I can image Java without overloading -- there would have to be a bit of
tweaking to admit multiple constructors, and it would be a bit of a pain
if a latter version of JComponent introduced a method whose name clashed with
one you had introduced in your custom subclass... but by and large Java
would be the same. Now image Java without overriding: it's life, but not
as we know it.

ps. I've been waiting years to drop fa�on de parler into conversation .
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jon Lee:
polymorphism and overloading are different concepts, not comparable...


Polymorphism is often used as a synonym for runtime polymorphism, but historically it actually is a much broader concept, and includes overloading. Search for polymorphism on wikipedia.org (or stupid forum software doesn't allow me to post the link here because of some special characters... :roll: )
[ December 09, 2005: Message edited by: Ilja Preuss ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh, Sachin,

try this code:



This should probably be part of our FAQ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic