Multiple choice technology web technology

Given: interface Hungry { void munch(E x); } interface Carnivore extends Hungry {} interface Herbivore extends Hungry {} abstract class Plant {} class Grass extends Plant {} abstract class Animal {} class Sheep extends Animal implements Herbivore { public void munch(Sheep x) {} } class Wolf extends Animal implements Carnivore { public void munch(Sheep x) {} } Which of the following changes (taken separately) would allow this code to compile? (Choose all that apply.)

  1. Change the Carnivore interface to interface Carnivore<E extends Plant> extends Hungry<E> {}

  2. Change the Herbivore interface to interface Herbivore<E extends Animal> extends Hungry<E> {}

  3. Change the Sheep class to class Sheep extends Animal implements Herbivore<Plant> { public void munch(Grass x) {} }

  4. Change the Sheep class to class Sheep extends Plant implements Carnivore<Wolf> { public void munch(Wolf x) {} }

  5. Change the Wolf class to class Wolf extends Animal implements Herbivore<Grass> { public void munch(Grass x) {} }

  6. No changes are necessary

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Sheep implements Herbivore, which requires Sheep to extend Plant because of interface Herbivore. Since Sheep extends Animal, this fails compilation. Changing Herbivore to interface Herbivore allows Sheep to be the type argument E because Sheep is an Animal.