146k views
2 votes
Consider the following class public abstract class Animal\{ public String name; public int age; public Animal(String name, int age) \{ this.name = name; this.age = age; \} public abstract String noise (); Write a concreate class called Cat that extends the Animal class. Cat objects will have two additional attributes called breed (a String) and isLongHaired (a boolean). The Cat class must have a single constructor that takes four inputs (name, age, breed, isLongHaired) and assigns them to their corresponding attributes properly. Be sure that you are not using attribute hiding. A Cat's noise is "moew" if the Cat is older then three years and "purr" otherwise. Do not worry about information hiding in this question.

1 Answer

3 votes

Final answer:

To create a Cat class that extends the Animal class, define two additional attributes and a constructor. The Cat's noise should be "meow" if the age is over 3, and "purr" otherwise.

Step-by-step explanation:

To create a concrete Cat class that extends the Animal class, we need to define two additional attributes: breed (String) and isLongHaired (boolean), and a constructor that takes four inputs and assigns them to the corresponding attributes. Here's an example of how the Cat class can be implemented:




  • public class Cat extends Animal {

  • private String breed;

  • private boolean isLongHaired;


  • public Cat(String name, int age, String breed, boolean isLongHaired) {

  • super(name, age);

  • this.breed = breed;

  • this.isLongHaired = isLongHaired;

  • }


  • public String noise() {

  • if (age > 3) {

  • return "meow";

  • } else {

  • return "purr";

  • }

  • }

  • }

User Beberlei
by
7.6k points