Question: Java Create a public class named Ship with fields for displacement and length. Include a constructor that requires parameters for both fields and get and
Create a public class named Ship with fields for displacement and length. Include a constructor that requires parameters for both fields and get and set methods for both fields. Include a toString method that displays the value of both fields. Create two public child classes of the Ship class named WindPoweredShip and PropellerPoweredShip. The WindPoweredShip class should have a field named numberMasts and a toString() method that shows the value of all of its fields. The WindPoweredShip should have a constructor with parameters for displacement, length, and numberMasts. Include get and set methods for all fields. The PropellerPoweredShip class should have a field named numberPropellers and a toString() method that shows the value of all of its fields. The PropellerPoweredShip class should have a constructor with parameters for displacement, length, and numberPropellers. Include get and set methods for all fields. Write a public class named ShipDemo that creates two WindPoweredShip objects and two PropellerPoweredShip objects. All four objects should be stored in a single array. The program should print each object in the array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
