Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

explain the flow of the program  RSS feed

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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 ]
 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!