This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "polymorphism" Watch "polymorphism" New topic
Author

polymorphism

Jyothi prakash alluri
Greenhorn

Joined: Jan 19, 2003
Posts: 2
Hi myself and my friend were caught in an argument. here it is.
I say method overloading and method overriding both comes under polymorphism concept.
but he says only method overriding comes under polymorphism. Not method overloading.
please clarify us.....
Thankx
[ January 27, 2003: Message edited by: Marilyn de Queiroz ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Here is my favorite conversation on this topic. You can find many more in this forum by searching on "polymorphism" and "overloading", but I think this one is the best.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Robbie shi
Greenhorn

Joined: Jan 05, 2003
Posts: 28
i agree with your friend.
only method overriding comes under polymorphism
you can use one kind of object perform differrent
Action by invoking same Function!!!
so that must be OVERRIDE!
----
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Polymorphism is method overriding. Method overloading is nothing more than a fancy naming scheme.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I don't think there is a definite answer.
There are people who refer to things like method overloading and templates as "static polymorphism". (Just do a google search.)
Others will argue that this isn't really polymorphism, as it isn't resolved at runtime (though I don't fully follow that argument).
Personally, I don't think it matters much. It isn't that atypical for words of a living language to have different meanings depending on context and/or user. The world doesn't end, nevertheless...
So just make sure that you are speaking about the same thing when you talk about polymorphism.


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
Joanne Fiorilli
Greenhorn

Joined: Jan 23, 2003
Posts: 5
Polymorphism requires late binding. Overriding has this, however, not overloading.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Joanne Fiorilli:
Polymorphism requires late binding.

Dynamic Polymorphism certainly requires late binding. Static Polymorphism doesn't.
No you could argue that static polymorphism isn't "true polymorphism". What value would lie in that?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Here's why I don't think overloading should be called polymorphism.
Overloading is nothing more than a convenient naming scheme. What horrible loss to the language would occur if we eliminated overloading? We would need to come up with unique names for our methods. So what? Every program would still work exactly as written (once the method names were made unique). No feature of the language would stop working. Overloading is a convenience like not having to use braces when you have only one statement in an if.
Overriding is a key feature to the language. If we removed overriding the language would cease to be useful. Think of all the programs that would cease working. The whole idea of interfaces and abstract classes would be pointless. Java would be no more useful than BASIC. (And I don't mean VB.)
That is why I don't think we should call overloading, polymorphism. It debases the concept of polymorphism by associating it with a trivial feature of the language. I know it is common to use "polymorphism" for both but it is also common to mix up "imply" and "infer". Just because everyone gets it wrong doesn't make it right.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Thomas Paul:
What horrible loss to the language would occur if we eliminated overloading?

It would increase source code coupling.
Imagine the following code:

Now you need to change factor to hold a double. The System.out.println would still work.
Without overloading, you needed to change the method call from printInt to printDouble, or something.
So, overloading reduces coupling - not as strongly as dynamic method dispatch does, but it does.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Ilja Preuss:
So, overloading reduces coupling - not as strongly as dynamic method dispatch does, but it does.

No, it doesn't reduce coupling because you still need to know the methods and parameters of the class whose methods you are calling. It does ease maintenance.
That's not to say that method overloading is not useful. But designing a system in Java without method overloading would be a trivial excercise. Designing a system without polymorphism would be a nightmare.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: polymorphism