Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We want to try to mimic multiple inheritance given the restrictions Java does pl

ID: 3687619 • Letter: W

Question

We want to try to mimic multiple inheritance given the restrictions Java does place on us. The code for the Food interface and Animal class can be found below.

public abstract class Animal {

private double weight;

protected Animal (double weight) {

this weight=weight;

}

public abstract void animalNoise();

{

public interface Food {

public abstract void howToEat();

}

Try to mimic multiple inheritance by extending the Animal class and implementing the Food interface. Take note of the abstract methods. Remember, we must implement these in any inheriting classes.

public abstract class Animal {

private double weight;

protected Animal (double weight) {

this weight=weight;

}

public abstract void animalNoise();

{

public interface Food {

public abstract void howToEat();

}

Explanation / Answer

Animal.java

public abstract class Animal {

   private double weight;
  
   public Animal(double weight) {
       this.weight = weight;
   }

   public abstract void animalNoise();
}

Fish..java

public class Fish extends Animal implements Food{

   String sound, eating;
  
   public Fish(double weight) {
       super(weight);
   }
  
   @Override
   public void animalNoise(){
       System.out.println("Fish: " + sound);
   }
  
   @Override
   public void howToEat(){
       System.out.println("Fish: " + eating);
   }

}

Food.java

public interface Food {
  
   public abstract void howToEat();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote