Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B -From genric & collections-Self Test

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Q10 of selftest in K & B which is


which has options


ans is B
I am not getting that why for option C to be correct we needs munch(Plant p) method instead of munch(Grass x)
also if there is any material which explains about type generic,I am really lost....n I suppose its an imp topic for exam
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

For option C to be correct we need munch(Plant p) method instead of munch(Grass x)!

Because when you replace E with Plant in Interface Herbivore, method's signature would become

void munch(Plant p);

But in the implementation of Sheep, method is overloaded as Grass is used as input parameter instead of Plant.

Since there is no implementation given in Sheep for munch(Plant x), code wont compile!

For this code to compile, either Sheep class has to be abstract or we have to add implementation for method munch(Plant x).

Hope you get it!

 
nitude gupta
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi your explaination was quite good but I am still confued abt all this



I suppose this is the current scenario
can you explain for each option how it is wrong because according to me the code should compile fine
no
Thank you....I am really not getting the concept I think
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic