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

compile-time polymorphism

 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One example would be method overloading.
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.

apart from that what can be compile time polymorphic ?
 
Henry Wong
author
Marshal
Pie
Posts: 20828
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 384
Java MyEclipse IDE Spring
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic