Question: Inheritance 5 . Implement the following inheritance hierarchy, including a test class that demonstrates polymorphism. ( 2 8 Points ) a ) Class Boat (

Inheritance
5. Implement the following inheritance hierarchy, including a test class that demonstrates polymorphism. (28 Points)
a) Class Boat (7 points)
stores the length of the boat as integer value
the constructor initializes the length of the boat.
It contains a getter and setter method for the length
it contains a move method, that prints "drift" when called
it overrides the toString method to return a dynamic string, e.g., "Boat(length: 9)"
b) Class RowBoat (5 points)
inherits from Boat
prints "drift", when its move method is called
overrides the toString method, that returns the following dynamic string, e.g., "RowBoat(length: 9)"
c) Class SailBoat (6 points)
inherits from Boat
prints "hoist sail', when its move method is called
overrides the toString method, that returns the following dynamic string, e.g., "SailBoat(length: 9)"
d) Class TestBoat contains a public static void main(String[ args) method, which implements the following tasks: (10 points)
declares and initializes a Boat object
declares and initializes a RowBoat object
declares and initializes a SailBoat object
adds all three objects to an ArrayList
iterates through the array list and calls the toString, as well as the move method polymorphically.
 Inheritance 5. Implement the following inheritance hierarchy, including a test class

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!