48.1k views
4 votes
Write a class for a Cat that is a subclass of Pet. In addition to a name and owner, a cat will have a breed and will say "meow" when it speaks. Additionally, a Cat is able to purr (print out "Purring..." to the console).

1 Answer

2 votes

Answer:

The Java class is given below with appropriate tags for better understanding

Step-by-step explanation:

public class Cat extends Pet{

private String breed;

public Cat(String name, String owner, String breed){

/* implementation not shown */

super(name, owner);

this.breed = breed;

}

public String getBreed() {

return breed;

}

public void setBreed(String breed) {

this.breed = breed;

}

public String speak(){ /* implementation not shown */

return "Purring…";

}

}

User IKushal
by
4.4k points