• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

polymorphism

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Polymorphism is method overriding. Method overloading is nothing more than a fancy naming scheme.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Polymorphism requires late binding. Overriding has this, however, not overloading.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic