Question
Create a base class called Animal, that has fields, constructors, and anything else you think you may need as you go along. It should also
Create a base class called Animal, that has fields, constructors, and anything else you think you may need as you go along. It should also have a method called speak(), to make the Animal say something (using System.out.println)
Create any two subclasses of the Animal class. Each subclass must have the following:
- At least one new field, with getter/setter methods
- A default constructor that sets its fields to default values, and also all the fields of it's base class to default values
- A parameterized constructor that accepts all fields from both the base (Animal) and new subclass fields
- Override the speak method to make it say something specific that an object of that class would say.
Create another subclass that extends any one of the two subclasses from step 2.The subclass in step 2 will serve as a super class for this new subclass. Each subclass must have the following:
- At least one new field, with getter/setter methods
- A default constructor that sets its fields to default values, and also all the fields of it's base class to default values
- A parameterized constructor that accepts all fields from both all super classes, and new subclass fields
- Override the speak method, to make it say something specific that an object of that class would say.
In a main method, create an Animal object, and at least one object of each subclass (3 objects), and stick all the objects in either an ArrayList or an array. Then just loop through (iterate) the ArrayList or array, and call the speak method for each object
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