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?

 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello EveryOne!

I have a confusion regarding compile time polymorphism ,let me explain my doubt first, as i know polymorphism is done only by the behavior(methods) of an Object, and object born at runtime by the JVM
but not at compile time,if there is no object at compile time,then how do we talk about behavior of an object without its existence ,method resolution should be done at runtime in the case of polymorphism based on runtime object but how it happens at compile time while there is no existence of object.I'm confused??
I'm curious to know, how we say, it is compile time polymorphism.??
I have a request to you all guys please, take a look on it and leave me your valuable and reasonable reply...so i'd be able to correct myself.
awaiting for your reply....
Thanks for your time

Regards:
Vivek


 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile time polymorphism is accomplished in Java through method overloading.
 
Divya Chandel
Ranch Hand
Posts: 47
MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Compile-time Example - Function Overloading
Run-time Example - Function Overriding, Interfaces.

Overriding is the example of run-time polymorphism
Overloading is the example of compile-time polymorphism

When we compile the class, the compiler binds the appropriate method to the object based on the method’s arguments. This is called early binding and this process is referred to as compile time polymorphism.
 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Divya Chandel wrote:

When we compile the class, the compiler binds the appropriate method to the object based on the method’s arguments.


Hi Divya,
thanks a lot, your answer is appreciable and really its good explanation ,here i have one question, does object exist(create) at compilation time of java code? only i'm getting confused in this line that object does not exist at compile time, only exist at runtime .

Divya Chandel wrote:
Overloading is the example of compile-time polymorphism.


here I'm agree with your answer ,here i'd like to arise one question to you . in real world, polymorphism happens by changing the behavior of an object with other, if we talk about in the case of programming language(JAVA) polymorphism concept is achieved by overloading and overriding also.please clear my doubt ...may be, my question is not meaningful but still i have doubt.
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
,here i have one question, does object exist(create) at compilation time of java code?

No, objects only exist at runtime.

I can't answer your second question because I'm sorry but I don't understand it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will find no agreement; if you ask a lot of people, many will say there is only runtime polymorphism, and compile‑time polymorphism is a misnomer.
 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You will find no agreement; if you ask a lot of people, many will say there is only runtime polymorphism, and compile‑time polymorphism is a misnomer.


thank you so much, Campbel .
yes, you are absolutely right, but as i discussed with some professional(who are well aware about java ) about one of the beautiful concept of OOP- polymorphism, then their statement about polymorphism was that.....
1-polymorphism is real world concept which done through the behavior of an real world object (Ex. a man can have different behavior ,through th behavior he can be know by many names like father , doctor,brother..etc )
2-we achieve polymorphism concept in java through the overloading or overriding of methods.
3-static polymorphism | compile time polymorphism | early binding all are same and done at compile time based on reference type.
4-dynamic binding | runtime polymorphism | late binding all are same and done at runtime and based on runtime object .

Campbell Ritchie wrote:
if you ask a lot of people, many will say there is only runtime polymorphism,


i'm agree with Campbell answer, because if polymorphism talk about different behavior of an single object, means if there is polymorphism then there must be exist an object and in java object exist only at runtime so according to this, Campbell answer is well considerable,and meaningful. but if it is true that there is only runtime polymorphism exist...then i'd be eager to know about the point- 3 mentioned above. ?

Thanks ...
vivek
 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
No, objects only exist at runtime.
I can't answer your second question because I'm sorry but I don't understand it.


Thanks..Tony for your valuable time and reply. i have rephrased my question and replied to Campbell ,Please have a look on that..
thanks in advance...
 
Winston Gutkowski
Bartender
Pie
Posts: 9498
50
Eclipse IDE Hibernate Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek Bhardwaj wrote:but if it is true that there is only runtime polymorphism exist...then i'd be eager to know about the point- 3 mentioned above. ?

My opinion: it doesn't exist. It is simply a term coined by some (probably lazy) technical writers to describe method overloading in terms that "everyone" (?) understands.

As far as I'm concerned "static [or 'compile time'] polymorphism" is an oxymoron.

Winston
 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Vivek Bhardwaj wrote:but if it is true that there is only runtime polymorphism exist...then i'd be eager to know about the point- 3 mentioned above. ?

My opinion: it doesn't exist. It is simply a term coined by some (probably lazy) technical writers to describe method overloading in terms that "everyone" (?) understands.

As far as I'm concerned "static [or 'compile time'] polymorphism" is an oxymoron.

Winston


Thank you so much, Winston for your time,given for this discussion to clear up. now i got whatever was missing..thanks to all
good day!

regards
Vivek
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic