Question: ( 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
