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

explain the flow of the program

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is an example of overloading.
Lets go through the code
c.eat calls the eat method in Cattle class.Now the Cattle class has two overloaded methods.
void eat(Mammal m) and void eat(Cattle c) as Cattle extends Mammal class
Now comes the trickest part...
The compiler looks at the passed argument's reference type(note it doesn't care about the object the reference actually contains).The argument's reference type is Mammal.Hence the void eat(Mammal m) method is called.
Hence the output is:
Mammal eats food.
-vinu.
[ May 09, 2005: Message edited by: vinuharan haran ]
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic