wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes compile-time polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compile-time polymorphism" Watch "compile-time polymorphism" New topic
Author

compile-time polymorphism

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

hi ranchers ,

there is runtime polymorphism in java , i have no doubt in that but Is there compile time polymorphism ?

if yes what could be the example of the case?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

One example would be method overloading.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

ok.

apart from that what can be compile time polymorphic ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18550
    
  40

naveen yadav wrote:
apart from that what can be compile time polymorphic ?



I think you also need to define "what is compile time polymorphism"?

For example, is polymorphism (overriding methods) truly runtime? There is definitely a runtime component, as the methods are resolved at runtime. But isn't there also a compile time component? It is the compiler that figures out the code that builds the jump tables, etc.



IMO, the definition isn't completely clear, certainly not enough to give you a clear answer.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

Henry Wong wrote:

I think you also need to define "what is compile time polymorphism"?
Henry


i meant to say that what are "other thing" in java which shows polymorphic nature at compile time ?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

naveen yadav wrote:
Henry Wong wrote:

I think you also need to define "what is compile time polymorphism"?
Henry


i meant to say that what are "other thing" in java which shows polymorphic nature at compile time ?


We know that. The problem is there are multiple valid definitions for polymorphism. If we don't know exaclty how you are defining it, we can't give you a precise or complete answer according to your definition.

Which brings us to the question: Why do you care? How will it help your understanding of Java or help you to write better code if somebody tells you that, "Behavior X is considered compile-time polymorphism"?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

Just to emphasise that how you're defining it matters, and how different people mean different things by it - I personally don't believe there is such a thing as "compile-time polymorphism". Not in Java, anyway. I consider polymorphism to mean that you perform the same action on different objects and they behave in different ways. I don't consider method overloading to meet this definition, as you're calling different methods (that just happen to have the same name). But others will take a different view.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

things get more clear http://www.coderanch.com/t/412204/java/java/Polymorphism-applies-overriding-not-overloading

thank you all.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6



How is that more clear? It says exactly the same things we've been telling you: That the answer to your question depends on your definition of "polymorphism," and that there is no one single universally accepted standard definition.
Chandraprakash Sarathe
Greenhorn

Joined: Jan 21, 2012
Posts: 16
Method overloading is compile time polymorphism , also operator overloading is compile time polymorphism.
Aren't you mixing compile time polymorphism with compile time behaviour of Java?


Chandraprakash Sarathe
http://javaved.blogspot.com
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Chandraprakash Sarathe wrote:Method overloading is compile time polymorphism , also operator overloading is compile time polymorphism.

It may or may not be, depending on one's interpretation of the term, as already discussed in this thread.


Aren't you mixing compile time polymorphism with compile time behaviour of Java?


No, we're discussing compile-time polymorphism as one aspect of Java's compile time behavior.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: compile-time polymorphism
 
Similar Threads
Overloading
Polymorphism applies to overriding, not to overloading
Whether Overloading is a way to implement Polymorphism?
polymorphism
Dynamic polymorphism and Overriding