Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are building a program to model different types of animals. You have been given the following abstract class for the Animal Time left
You are building a program to model different types of animals. You have been given the following abstract class for the Animal Time left 1:34:25 class: public abstract class Animal { private String name; private int age; public Animal(String name, int age) ( 1 this.name name; this.age age; } public String getName() { return name; } public int getAge() ( return age; } public abstract String getSound(); Create two classes that extend the Animal class: Cat and Dog. The Cat class should have an additional instance variable numLives, and a constructor that takes name, age, and numLives as parameters. The Cat class should also override the getsound() method to return "Meow". The Dog class should have an additional instance variable breed, and a constructor that takes name, age, and breed as parameters. The Dog class should also override the getSound() method to return "Woof". Write the code for the Cat and Dog classes, implementing the Animal abstract class with the additional methods specified above. The constructors in the subclasses must use super and call the superclass constructor.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
The task involves creating two subclasses of the abstract class Animal Cat and Dog Lets write the co...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