Question
JAVA OOP: Interface and Abstract Classes a. Create anAnimalclass, which is the abstract superclass of all animals. 1. Declare a protected integer attribute called legs,
a. Create anAnimalclass, which is the abstract superclass of all animals.
1. Declare a protected integer attribute called legs, which records the number of legs for this animal.
2. Define a protected constructor that initializes the legs attribute.
3. Declare an abstract method called eat.
4. Declare a concrete method called walk that prints out something about how the animals walks (include the number of legs).
b. Create aSpiderClass
1. The spider class extends the animal class
2. Define a default constructor that calls the superclass constructor to specify that all spiders have eight legs.
3. Implement the eat method.
c. Create aPetinterface specified by the UML diagram below
d. Create theRabbitclass that extendsAnimaland implementsPet.
1. This class must include a string attribute to store the name of the pet.
2. Define a constructor that takes one string parameter that specifies the rabbit's name. This constructor must also call the superclass constructor to specify that all rabbits have four legs.
3. Define another constructor that takes no parameters. Have this constructor call the previous constructor(using the this keyword) and pass an empty string as the argument.
4. Implement the Pet interface methods.
5. Implement the eat method.
e. Create theFishclass. Override the Animal methods to specify that fish cannot walk and don't have legs.
f. Create aTestAnimalsprogram. Have the main method created and manipulate the instance of the classes you created above: Start with:
1. Creating instances of fish, rabbit, spider.
2. Experimenting on: Calling methods in each object
3. Using polymorphism
4. Using super to call superclass methods.
> Pet Animal #legs:int #Animal(legs:int) +walk() +eat() +getName : String +setName(name : String) +play() Rabbit" v:shapes="Picture_x0020_20">
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