Question: Java Programming Create a Battleship parent class and a Captain sub class which will inherit from the super class. Write the code for the parent
Java Programming Create a Battleship parent class and a Captain sub class which will inherit from the super class.
- Write the code for the parent class. It must contain the following:
//Header
//Declare instance variable battleshipname
//Declare accessor for the instance variable
//Declare mutator for the instance variable
//declare a method sail which by default prints I can not sail now
- We now write the subclass Captain which will inherit from the parent class.
// Header
//Declare a routine standby which will set boats own behavior by printing Boat //battleshipname via accessor is starting.
// Override the super class behavior of the sail() method by // declaring a sail() method in which you call sail ()
- Test class for inheritance behavior Write a main program in which Captain class is inheriting behavior and properties of Battleship class and overriding the sail() method so that it has its own behavior.
public class Inheritance {
// Header for main class
// Instantiate a Captain object with Battleship reference
//Use the inherited mutator to set this ships name to Bismarck
// Allow the battleship to sail
}
}
You should not miss these questions. The output of this program is ___________________ . The polymorphic routine is ____________. If I had instantiated mycaptain with a BattleShip signature, mycaptain = new Battleship();
the output would have been __________________.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
