Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Inheritance 5 . Implement the following inheritance hierarchy, including a test class that demonstrates polymorphism. ( 2 8 Points ) a ) Class Boat (
Inheritance
Implement the following inheritance hierarchy, including a test class that demonstrates polymorphism. Points
a Class Boat 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, eg "Boatlength:
b Class RowBoat points
inherits from Boat
prints "drift", when its move method is called
overrides the toString method, that returns the following dynamic string, eg "RowBoatlength:
c Class SailBoat points
inherits from Boat
prints "hoist sail', when its move method is called
overrides the toString method, that returns the following dynamic string, eg "SailBoatlength:
d Class TestBoat contains a public static void mainString args method, which implements the following tasks: 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.
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