• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Polymorphism applies to overriding, not to overloading

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no term like compile time polymorphism in java.
 
Marshal
Posts: 73022
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 73022
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
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 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
  • 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:


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 !
reply
    Bookmark Topic Watch Topic
  • New Topic