Answered step by step
Verified Expert Solution
Link Copied!

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
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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

How do they research and outline writing projects?

Answered: 1 week ago