Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBianca Christian
3,524 PointsIm completing a polymorphism task and unsure how to 'implement an abstract method' across 3 classes
The instructions are:
- In the Animal class: add a new abstract method eat() that takes a Food object as an argument.
- .provide an implementation for eat(). In each case print out a message saying that the animal is eating the given food. 3.. update Wolf class and Parrot class so that Wolf extends Carnivore and Parrot extends Omnivore.
This is what i have so far import java.time.LocalDate; import java.time.Period; public abstract class Omnivore extends Animal{
public Omnivore(LocalDate dob, String n){
super(dob, n);
}
public static void main(String[] args) {
omni.eat(Meat);
}
}
import java.time.LocalDate;
import java.time.Period;
public abstract class Animal
{
int age;
String name;
LocalDate dateOfBirth;
Wolf wolf1;
Food foodObj;
//constructor with parameters of date and name
public Animal(LocalDate dob, String name){
dateOfBirth = dob;
this.name = name;
}
//removed irrelevant code
//guaranteeing that subclasses will provide a noise
public abstract void makeNoise(String noise);
public abstract void eat(Food foodObj);
}