This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B -From genric & collections-Self Test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B -From genric & collections-Self Test" Watch "K&B -From genric & collections-Self Test" New topic
Author

K&B -From genric & collections-Self Test

nitude gupta
Ranch Hand

Joined: Sep 04, 2008
Posts: 34
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
M Srilatha
Ranch Hand

Joined: Aug 27, 2008
Posts: 137
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!


Thanks,<br />Srilatha M
nitude gupta
Ranch Hand

Joined: Sep 04, 2008
Posts: 34
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: K&B -From genric & collections-Self Test
 
Similar Threads
Generic Types extending Abstract implementing Interface
Diubt on Generics, Q.10 from K&b book
page# 616 question# 10
K&B collection and generic question
Generics