Question: Make the necessary Java coding by preserving the hierarchical structure, variables and methods shown in the UML class diagram below. The walk ( ) method

Make the necessary Java coding by preserving the hierarchical structure, variables and methods shown in the UML class diagram below. The walk() method will print "walking with 8 legs" along with the number of legs of that animal for which animal it is called. The number of legs of the relevant animal will be kept only in the Animal abstract class and the class variable named legs, as seen in the diagram.
- For whichever animal the eat() method is called, a description such as "is eating" will be printed on the screen along with the type of that animal. Ex: ''Cat is eating.''
- legs class variable will be set only with the help of constructors.
- The number of legs for the spider will always be given as 8 by sending a parameter to the constructor.
- All cats created without names will be named "Tom" and the number of legs of all cats will be given as 4 by sending a parameter to the constructor.
- For Fish objects, the number of legs will be 0 and the walk() method will print a statement saying "Can not walk" on the screen.
- Additionally, in addition to all classes, define a class that contains a main method called Test. In this class, create the following objects exactly as written below and call the eat() and walk() methods one by one on these objects.
Fish f = new Cat (''Fluffy'');
Animal a = new Fish();
Animal s = new Spider();
Pet p = new Cat();
- Call the play() method by making the necessary transformation (cast) using the object named p
- Call the swim() method by making the necessary transformation (cast) using the object named a.
 Make the necessary Java coding by preserving the hierarchical structure, variables

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!