• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compile time polymorphism?

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


 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compile time polymorphism is accomplished in Java through method overloading.
 
Ranch Hand
Posts: 47
MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3323
86
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79180
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic