Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock

The task involves creating two subclasses of the abstract class Animal Cat and Dog Lets write the co... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!