Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( b ) Given the class Ship that has a name, berth, and speed write a class BattleShip, demonstrating BattleShip IS - A Ship relationship
b Given the class Ship that has a name, berth, and speed write a class BattleShip, demonstrating BattleShip ISA Ship relationship using inheritance.
Class BattleShip requires an gunNo and helipadCount both of type int.
Class Battle Ship must have a constructor, getter and setter methods, and a toString method.
public class Ship
private String name;
private String berth;
private int speed;
public ShipString name, String berth, int speed
this.name name;
this. berth berth;
this.speed speed;
;
public String getName
return name;
i
public void setNameString name
this.name name;
i
public String getBerth :
return berth;
;
public void setBerthString berth :
this. berth berth;
;
public int getSpeed :
return speed;
Page of
;
public void setSpeedint speed
this.speed speed;
a Override
public String toString
return "Ship "name name berth berth speed speed ;
;
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