File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism applies to overriding, not to overloading

 
rakesh kumar nampally
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Polymorphism applies to overriding, not to overloading.

I am bit confused with this statement. Can any one please justify this.
 
ram kumar
Ranch Hand
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !

 
Brij Garg
Ranch Hand
Posts: 234
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no term like compile time polymorphism in java.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ram kumar
Ranch Hand
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic