aspose file tools*
The moose likes Java in General 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "compile time polymorphism?" Watch "compile time polymorphism?" New topic
Author

compile time polymorphism?

viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74

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

Joined: Aug 07, 2007
Posts: 1939
    
  28
Compile time polymorphism is accomplished in Java through method overloading.
Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 45


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.

Divya
SCJP1.6
viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74

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

Joined: Aug 07, 2007
Posts: 1939
    
  28
,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

Joined: Oct 13, 2005
Posts: 36478
    
  16
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

Joined: Nov 07, 2011
Posts: 74

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

Joined: Nov 07, 2011
Posts: 74

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

Joined: Mar 17, 2011
Posts: 7045
    
  16

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


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
viki Bhardwaj
Ranch Hand

Joined: Nov 07, 2011
Posts: 74

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
 
subject: compile time polymorphism?
 
Similar Threads
Understanding creating a "super" class obj from a "subclass" object
The "this" keyword and the constructor.
PGPPublicKeyRingCollection doubts
Simple JPA application on TOMEE
Can we achieve the effects of GridBagLayout in other Layouts?