This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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
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.
When we compile the class, the compiler binds the appropriate method to the object based on the method’s arguments.
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.
Joined: Aug 07, 2007
,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 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. ?