Question
Consider the following class representing a Pet. Write a class for a Cat that is a subclass of Pet. In addition to a name and
Consider the following class representing a Pet.
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).
public class Pet{
//creates a Pet with the given name & owner
public Pet(String name, String owner){
/* implementation not shown */
}
//returns the name of the current owner
public String getOwner()
{ /* implementation not shown */ }
//changes the owner of this Pet
public void changeOwner(String owner){
/* implementation not shown */ } //gets the name of this pet
public String getName()
{ /* implementation not shown */ }
//this pet has no sound, returns empty string
public String speak(){ /* implementation not shown */ }
//There may be other variables, constructors, and methods not shown. }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started