Question
Question 2: [20 marks] Define a java structure (code) that can represent Animals . Animals a move behavior; they can move() . By default, when
Question 2: [20 marks]
Define a java structure (code) that can represent Animals. Animals a move behavior; they can move(). By default, when an animal moves, the text This animal moves forward is displayed. A general Animal should not be able to be instantiated.
Define also two classes, Goose and Lynx, that are Animals. Both Goose and Lynx behave such that the word animal which is displayed in move(), is replaced with goose or lynx in the displayedmessage by the appropriate classes.
For example, the messages displayed with a Goose objects move() method is This goose movesforward. The same with Lynx object.
Finally, any instance of Goose can fly(), just as any Flying object can. An Airplane is also a Flying object. Define the Airplane class such that it is Flying and make sure that any instance of Goose is also Flying. The specific behaviors when instances of either class fly() are:
Goose object: This goose flies with wings flapping Airplaneobject: This airplane flies with engine running.
Instances of either Goose or Airplane should be able to be stored in a variable of type Flying.
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