aspose file tools*
The moose likes Beginning Java and the fly likes is overloading example of static or dynamic polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "is overloading example of static or dynamic polymorphism" Watch "is overloading example of static or dynamic polymorphism" New topic
Author

is overloading example of static or dynamic polymorphism

Ramesh Chandra
Greenhorn

Joined: Oct 20, 2005
Posts: 17
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

For what reason do you want to know? Is there some example code you have questions about?


My Blog: Down Home Country Coding with Scott Selikoff
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
But then if you override an overloaded method ...


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jon Lee
Ranch Hand

Joined: Mar 04, 2005
Posts: 134
polymorphism and overloading are different concepts, not comparable...


SCJP 5.0 - 98% (2007)<br />SCWCD 1.4 - 97% (2007)
Ramesh Chandra
Greenhorn

Joined: Oct 20, 2005
Posts: 17
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

Joined: Dec 07, 2005
Posts: 100
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

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Dec 07, 2005
Posts: 100
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

Joined: Sep 16, 2005
Posts: 1780
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 .


There is no emoticon for what I am feeling!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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 ]

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Ramesh, Sachin,

try this code:



This should probably be part of our FAQ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is overloading example of static or dynamic polymorphism