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

The compilation fails because Sheep implements Herbivore, but Herbivore requires E extends Plant while Sheep extends Animal (not Plant). Changing Herbivore to accept E extends Animal fixes this since Sheep is an Animal. Carnivore already works correctly because it accepts E extends Animal, and Sheep qualifies.