File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading is Polymorphism? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading is Polymorphism?" Watch "Overloading is Polymorphism?" New topic
Author

Overloading is Polymorphism?

Jim Crawford
Greenhorn

Joined: Jan 31, 2002
Posts: 14
Any clarity on this issue? It seems to be something people don't really agree on.
My view is that overloading isn't polymorphism. The term (polymorphism) is sometimes loosely used, but then there is a problem with what it really means.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

This has been here debated many times before.
Please do a search in this forum or in the Java in General forums.


Junilu - [How to Ask Questions] [How to Answer Questions]
Len White
Greenhorn

Joined: Jan 08, 2002
Posts: 9
Originally posted by Jade McClooney:
Any clarity on this issue? It seems to be something people don't really agree on.
My view is that overloading isn't polymorphism. The term (polymorphism) is sometimes loosely used, but then there is a problem with what it really means.

You are correct. Overloading is not polymorphism. You have polymorphism only if you can send the same message to two different methods. With overloaded methods, you have to use different messages. Polymorphism boils down to one simple idea: same message, different method.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Jade McClooney:
Any clarity on this issue? It seems to be something people don't really agree on.
My view is that overloading isn't polymorphism. The term (polymorphism) is sometimes loosely used, but then there is a problem with what it really means.

This has been debated? Why? They're not the same thing. Period. Overloading allows you to give multiple method signatures to the same method name and ploymorphism is the effect of having an object (declared as a parent class) behave in the specific manner unique to the child class that is assigned to that variable at run-time. Do these things sound the same?
Corey
[ January 31, 2002: Message edited by: Corey McGlone ]

SCJP Tipline, etc.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Fellas (aka Corey and Len), I'm sorry to disagree with you BUT
Overloading IS one type of polymorphism !!!
From webopedia.com

polymorphism
Generally, the ability to appear in many forms. In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different circumference methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the circumference method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language (OOPL).
The type of polymorphism described above is sometimes called parametric polymorphism to distinguish it from another type of polymorphism called overloading.


Overloading
In programming languages, a feature that allows an object to have different meanings depending on its context. The term is used most often in reference to operators that can behave differently depending on the data type, or class, of the operands. For example, x+y can mean different things depending on whether x and y are simple integers or complex data structures.
Not all programming languages support overloading but it is a feature of most object-oriented languages, including C++ and Java. Overloading is one type of polymorphism.

HIH
[ January 31, 2002: Message edited by: Valentin Crettaz ]
[ January 31, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

I'm with Valentin on this.
That evens up score and hopefully we can leave it at that. If you want to find other opinions, please do a search for previous threads.
The number of times this topic has been beaten to death, you'd think it was a cat or something...
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
The number of times this topic has been beaten to death, you'd think it was a cat or something...


Poor little animals...
Junilu, I don't see many cats being beaten to death around here... Is it a local practice or what?
(Jane, Angela, sorry for the temporary hijack )
[ January 31, 2002: Message edited by: Valentin Crettaz ]
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Of course, if we aren't supposed to ever re-discuss something that has already been discussed, we should just close this forum and create a bunch of FAQ links, since every topic seems to have been discussed already. :roll:
How many times do you think the works of Shakespear get debated each year in Universities around the world?
I think debate is a good thing, even when the subject has already been discussed before
And I agree with the original response, that overloading is NOT polymorphism, but is an import PART of what polymorphism is.
Ie, there is no IS-A relationship between polymorphism and overloading. More like a HAS-A relationship.
Rob
[ January 31, 2002: Message edited by: Rob Ross ]

Rob
SCJP 1.4
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Rob,
what Junilu wanted to say is that some people seems to be lazy around here by not using the search engine...
Your last sentence doesn't make much sense since overriding is in direct relationship with polymorphism, I guess you meant overloading...
Ok forget it I see that you corrected that

Both overloading and overriding are related to polymorphism since they permit to apply different treatments to objects depending on their run-time type.
[ January 31, 2002: Message edited by: Valentin Crettaz ]
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Originally posted by Valentin Crettaz:
Your last sentence doesn't make much sense since overriding is in direct relationship with polymorphism, I guess you meant overloading...
Ok forget it I see that you corrected that


Hehe yes you're too fast for me.
Does anyone else ever have the problem where they tell their fingers to type a certain word but your fingers decide another word is better, without telling you??

I hate that!

Rob
[ January 31, 2002: Message edited by: Rob Ross ]
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi all,
i will also go with Val for this. forget about Java for a moment and u'll find this concept in C++ literature as well.
polymorphism can be compile time (which is the overloading) or runtime (RTT = Run Time Type detection of objects) which C++ calls Virtual Functions (in Java there is no keyword call virtual but its automatically virtual when u override things in child class). RTT can b also applied to the first def Val gave about Run Time Class Detection (Shape etc classes...)
Rob, as far as 'm concerned i don see what i type as i think when i type about what to type...my fingers automatically runs across appropriate keys (backspace also when i do sth wrong)...

regard
maulin
Erik Dark
Ranch Hand

Joined: Jan 28, 2002
Posts: 107
OVERLOADING IS NOT POLYMORPHISM !
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Originally posted by Erik Dark:
OVERLOADING IS NOT POLYMORPHISM !

Erik, no need to shout your neck off
Maybe you should explain your statement so that everybody is clear about that.
We haven't said that overloading IS polymorphism but that overloading plays a role in polymorphism which is slightly different.
In case you haven't read all messages in this thread and just answered something, note that I provided some definitions above and other encyclopedia seem to back those up (one more is below). So please enlighten us. Thanks in advance
From Whatis.com

In object-oriented programming, polymorphism (from the Greek meaning "having multiple forms") is the characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form. There are several different kinds of polymorphism.
1) A variable with a given name may be allowed to have different forms and the program can determine which form of the variable to use at the time of execution. For example, a variable named USERID may be capable of being either an integer (whole number) or a string of characters (perhaps because the programmer wants to allow a user to enter a user ID as either an employee number - an integer - or with a name - a string of characters). By giving the program a way to distinguish which form is being handled in each case, either kind can be recognized and handled.
2) A named function can also vary depending on the parameters it is given. For example, if given a variable that is an integer, the function chosen would be to seek a match against a list of employee numbers; if the variable were a string, it would seek a match against a list of names. In either case, both functions would be known in the program by the same name. This type of polymorphism is sometimes known as overloading.

HIH
[ January 31, 2002: Message edited by: Valentin Crettaz ]
Jim Crawford
Greenhorn

Joined: Jan 31, 2002
Posts: 14
I guess there isn't much clarity after all. Its probably just one of those things that are there for people to debate over. Wasn't it fun? (haha)
Sorry I didn't search a real lot, but I've searched other places and I just felt like feeling the water.. or something.
Someone quoted James Gosling out of The Java Language (I think that's what the book is called) where he sort of said its overloading isn't polymorphism. I wish that book was availible online. Spent too much on these kind of books already.
No hard facts here, but who cares. It wouldn't really make a difference to the programs we write right?

Cheers.
sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
I just read through Val's replies..
I guess he has given an excellent explaination for the concerning matter..
Great Explaination Val.Keep it up.
Sonir
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

Originally posted by Jade McClooney:
I guess there isn't much clarity after all. Its probably just one of those things that are there for people to debate over. Wasn't it fun? (haha)...
No hard facts here, but who cares. It wouldn't really make a difference to the programs we write right?

My thoughts exactly!
toh-mA-tohs, toh-ma-tohs --- whatever... they're still pa-ta-tas to me
NOW, can we let this thing RIP? (at least until the next search-challenged person comes along)
Junilu
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
Originally posted by Junilu Lacar:

NOW, can we let this thing RIP?
Junilu

You want to kill polymorphism?
[ February 01, 2002: Message edited by: Younes Essouabni ]

Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
 
wood burning stoves
 
subject: Overloading is Polymorphism?