jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Polymorphism & overloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Polymorphism & overloading" Watch "Polymorphism & overloading" New topic

Polymorphism & overloading

Marium Hasan

Joined: Oct 03, 2001
Posts: 12

I had a problem.
there is a question?
Is overloading an example/type of Polymorphism?
i have tried a simulator (jxam) & the options were:
1) overloading
2) overriding
2,3 & 4 th options were not correct , I have checked overriding
but the answer was overloading.
Also, i have study in the notes of Velmurugan of it that
Overloading is an example of Poly.
What is the truth?
Plz help , its urgent
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2591

polymorphism means "many forms". Overloading definitely is an example of (static) polymorphism, as one function can take many form. But, overriding is also dynamic polymorphism AFAIK. But I have seen notes saying that *only* overloading is polymorphism, which beats me.
I suggest you post this to "Programmer Certfication Study" forum, you are most likely to get correct answer there.
- Manish
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2591

I did little research (google of course!!!).
Overriding is polymorphism, in fact more so compared to overloading, which is also known as ad hoc polymorphism. Here's the link - http://www.cs.olemiss.edu/~hcc/softArch/notes/budd12.html
But then, if you have to choose only one as a correct answer, which one you'll choose? I'll go for overriding.
- Manish
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Overriding replaces the overridden method from the superclass with another method with the same argument signature and return type. That is, it's a new method that is using the skeleton of the old method - you can even use part of the old method by calling super()
Overloading on the other hand is a completely new method that uses the same name - with different argument signature and possibly return type - for the programmers convenience. There is no connection between the two methods.

Hope that helps,

Terry Doyle
Sun Certified Programmer for Java 2 Platform

Raising Flares debut album 'Ignition' out now


Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Well there is some debate about the terminology. In my opinion, if there is no late binding (as in over-riding) it is NOT polymorphism. But not everyone shares that definition.
Here is a debate that we had some time ago on that very subject: http://www.javaranch.com/ubb/Forum24/HTML/009465.html

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link: http://aspose.com/file-tools
subject: Polymorphism & overloading
It's not a secret anymore!