File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Head First Android 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

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

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
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
It's not a secret anymore!