• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Generics - how to make a Sheep eat Grass

Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a question about problem 10 in the Self Test of the chapter 7 in SCJP 5 book. I got the answer wrong, however, looking at the solution, when you change Herbivore to extend Animal, the munch() method defined by Hungry now has the Sheep eating the Sheep. Just for my own clarification and to help me better grasp generics, how would you go about changing the code sample so that the sheep could eat grass?

I came up with a possible solution, but it required eliminating Herbivore extending Hungry and then having Sheep implement both interfaces seperately. Would there have been a better alternative approach?

[ May 05, 2006: Message edited by: James Ridley ]
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic