Guest User

Untitled

a guest
Apr 26th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. public abstract class Carnivore extends Animal
  2. {
  3. public Carnivore(String newName, int newAge)
  4. {
  5. super(newName, newAge);
  6. }
  7.  
  8. public void eat(Food food) throws Exception
  9. {
  10. if (food instanceof Meat)
  11. {
  12. System.out.println("The carnivore is eating " +food.getFoodName());
  13. }
  14.  
  15. if (food instanceof Plant)
  16. {
  17. throw new Exception("IncorrectFoodType");
  18. }
  19. }
  20. }
Add Comment
Please, Sign In to add comment