aspose file tools*
The moose likes Beginning Java and the fly likes Polymorphism applies to overriding, not to overloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Polymorphism applies to overriding, not to overloading" Watch "Polymorphism applies to overriding, not to overloading" New topic
Author

Polymorphism applies to overriding, not to overloading

rakesh kumar nampally
Ranch Hand

Joined: Feb 03, 2007
Posts: 46
Hi,

Polymorphism applies to overriding, not to overloading.

I am bit confused with this statement. Can any one please justify this.


thanks & regards, Rakesh
ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
Originally posted by rakesh kumar nampally:
Hi,

Polymorphism applies to overriding, not to overloading.

I am bit confused with this statement. Can any one please justify this.


Polymorphism is of two kinds !
Method Overloading - Compile time Polymorphism
Method Over riding - Run time Polymorphism

google/Wiki that to know more !



Discussion - the powerfull way to excellence!
Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234
There is no term like compile time polymorphism in java.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
We usually use polymorphism to mean different binding at run-time, which to all intents and purposes means overridden instance methods. This means different objects can display different behaviour at run-time, even though they were declared as the same type.

You can't override fields or static methods. Those bind at compile-time, so there is no chance of changing behaviour at run-time.
ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
Originally posted by Campbell Ritchie:
We usually use polymorphism to mean different binding at run-time, which to all intents and purposes means overridden instance methods. This means different objects can display different behaviour at run-time, even though they were declared as the same type.

You can't override fields or static methods. Those bind at compile-time, so there is no chance of changing behaviour at run-time.


Hi Cambell !

would you just clarify us of what brij garg said !

As nothing in the name "compile time polymorphism". Is that true ?

What do you call, say

you overload a method in the same class.

like :




In the above code i never say / call the method by its name(not distinct) i say that with the parameters to the compiler - identify and resolve yourself the method call to be made based on the parameters supplied.

Compiler resolves that by the technique of compile time polymorphism.

Since, polymorphism applied at compile time.

what do you call this other than calling it compile time polymorphism!

please clarify if am wrong ! - brij
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
Some people call that compile polymorphism, I will grant you, but I don't think it is a good term. Real polymorphism is done via binding at run-time, and what you have here is the compiler finding two distinct methods and calling them. The methods might have the same identifier, but with different parameters they have different signatures so the compiler sees them as different just as if you had written "method1" and "method2."
ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
Originally posted by Campbell Ritchie:
Some people call that compile polymorphism, I will grant you, but I don't think it is a good term. Real polymorphism is done via binding at run-time, and what you have here is the compiler finding two distinct methods and calling them. The methods might have the same identifier, but with different parameters they have different signatures so the compiler sees them as different just as if you had written "method1" and "method2."


Thanks on your suggesstion !

I will sit tight calling it as compile time polymorphism (basically, am from a c++ background)!

I just wanted to clarify whether, my understanding about that would go wrong !
Now, am comfortable - for granting me to call as Compile time Polymorphism.




[ October 08, 2008: Message edited by: ram kumar ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Campbell Ritchie:
Some people call that compile polymorphism, I will grant you, but I don't think it is a good term.


Actually, the term is in quite wide use, and already was, long before the existence of Java. So, even if you don't like it, saying that such a thing doesn't exist is plain wrong.


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
ram kumar
Ranch Hand

Joined: May 22, 2008
Posts: 146
Originally posted by Ilja Preuss:


Actually, the term is in quite wide use, and already was, long before the existence of Java. So, even if you don't like it, saying that such a thing doesn't exist is plain wrong.



Thanks fo coming in !

Thanks Clarifying us in this !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphism applies to overriding, not to overloading