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

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!