Hi,
why C is invalid
if we change the code and put option c there then we have
Now at 1 sheep implements Herbivore interface with type Plant.This is correct.But see Herbivore interface is also extending Hungry interface and method munch in Hungry becomes
Now this is the problem,Munch method in class Sheep has Grass as its argument,so method munch of interface Hungry is not correctly implemented here.
why D is wrong
Now if we put option D in the code then we have
Class Wolf is implementing Carnivore<Sheep>,problem here is with generic type sheep.Carnivore interface has generic type <E extends Animal> i.e. E should be sub type of Animal.But in above code it is clear that Sheep is extending Plant not Animal.So this code will give compiler error.
I hope this helps you.
Sunny Mattas
SCJP5