Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Overloading" Watch "Overloading" New topic
Author

Overloading

Smitha Ballikar
Ranch Hand

Joined: Aug 02, 2005
Posts: 99
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
The subject of this question gives the answer.
Overloading! i.e execution of methods is decided at compile time itself, not at runtime.
So, It was already decided that Mammal's method will be executed irrespective of which object is being referred by "h".
[ August 09, 2005: Message edited by: Arulkumar Gopalan ]

Anbudan & Mahalo,<br />Arul<br /> <br />-Not a sun certified Java professional :-)
Smitha Ballikar
Ranch Hand

Joined: Aug 02, 2005
Posts: 99

So, It was already decided that Mammal's method will be executed irrespective of which object is being


Hi Arul,

I still didnt get the point.Even if it is decided at compile time Why the method of class mammal is executed.Can you please explain in depth..
Thanks..
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104
- Overloading is driven by parameters declared in the methods
- Objects are created at run time only.
- Compiler has no idea on what object is being referred by a reference variable.
Are we clear on these points?

According to the compiler, the method to be called is which ever has Mammal's reference as parameter, no matter what does it actually refer. So, it does execute Mammal's method.
Smitha Ballikar
Ranch Hand

Joined: Aug 02, 2005
Posts: 99
Hi Arul,

Thanks for the explanation...
I did understand that the method is called based on the type of parameter passed.I am also clear that objects are created at runtime.

But I have a small confusion in my concept. When do we actually check the type of object being referenced and call the method of that particular object??Is it in overriding?

Thanks..
Arulkumar Gopalan
Ranch Hand

Joined: Oct 13, 2003
Posts: 104

When do we actually check the type of object being referenced and call the method of that particular object??Is it in overriding

Yes, it is overriding, which is acting on the principle "A super class variable can refer a sub class object". So, depending upon the object being referred the appropriate method will be invoked at run time.

Little thing to remember everything:
Overloading: Compile time polymorphism
Overriding: Runtime polymorphism
[ August 09, 2005: Message edited by: Arulkumar Gopalan ]
Smitha Ballikar
Ranch Hand

Joined: Aug 02, 2005
Posts: 99
Hi Arul,

Got it Now!!!

Thanks..
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Overloading
 
Similar Threads
output
explain the flow of the program
Question related to overridding
polymorphism
Overloading