Question: Java Question: In this question, you will demonstrate your knowledge of inheritance. The parent class is Animal, while the subclass is Cat. Implement the classes
Java Question:


In this question, you will demonstrate your knowledge of inheritance. The parent class is Animal, while the subclass is Cat. Implement the classes below using the following instructions (25 marks): Animal Class Attributes isVegetarian-eg, true/false name - e.g., "Rusty" name e.g., "Rusty" * Constructor * accepts isVegetarian and name as arguments/parameters and sets the class attributes to the arguments/parameters Methods * getVegetarian0 - returns if they are vegetarian or not * setVegetarian(boolean isVegetarian) - sets vegetarian status of Animal getName0-returns the name of the animal * setName(String name) - sets name of the Animal * toString) - returns the name and vegetarian status of the Animal eg, Hi, I'm an Animal named Rusty, and I'm vegetarian" Cat Class Attributes numWhiskers - e.g., 32 * Constructor accepts isVegetarian, name, and numWhiskers as inputs and sets the private attribute values to the inputs * Methods * * getNumWhiskersO - returns the number of whiskers setNumWhiskers(int numWhiskers) 0 sets the number of whiskers of the cat, but cannot set numwhiskers to if num whiskers is a valid number (>=0), return true if numWhiskers is not a valid number, return false o o toString0-returns the name, vegetarian status, and number of whiskers of the cat e.g., Hi, I'm a Cat named Swaggy, I'm vegetarian, and I have 32 whiskers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
