Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Overloading

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Smitha Ballikar
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- 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
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Arul,

Got it Now!!!

Thanks..
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic