examples/src/main/java/animals/Carnivorous.java
2026-07-19 00:27:39 +03:00

26 lines
622 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package animals;
import food.Food;
import food.Meat;
public abstract class Carnivorous extends Animal{
public Carnivorous() {}
public Carnivorous(String name) {
super(name);
}
@Override
public void eat(Food food) {
int satiety = this.getSatiety();
if (food instanceof Meat) {
satiety += food.getEnergy();
this.setSatiety(satiety);
System.out.println("Животное ест.");
}
else {
System.out.println("Не получилось. Это животное ест только мясо.");
}
}
}