A game has 1 PlayerShip called \"player\" and 3 instances of EnemyShip called \"
ID: 3895569 • Letter: A
Question
A game has 1 PlayerShip called "player" and 3 instances of EnemyShip called "enemy1","enemy2" and "enemy3"
A constructor for class Game creates the player ship and three enemy ships. A game has 1 PlayerShip called "player" and 3 instances of EnemyShip called "enemy1","enemy2" and "enemy3"
A constructor for class Game creates the player ship and three enemy ships. public class Game // instance variables replace the example below with your own private PlayerShip player; private EnemyShip enemy1; private EnemyShip enemy2; private EnemyShip enemy3 public Game() PlayerShip player new PlayerShip(); EnemyShip enemy1new EnemyShip(); EnemyShip enemy2new EnemyShip() EnemyShip enemy3new EnemyShip():
Explanation / Answer
public class Game{
private PlayerShip player;
private EnemyShip enemy1;
private EnemyShip enemy2;
private EnemyShip enemy3;
public Game(){
// Since Game class already defined player and enemy object in constructor we just need to initialize instead of creating new object again.
player = new PlayerShip();
enemy1 = new EnemyShip();
enemy2 = new EnemyShip();
enemy3 = new EnemyShip();
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.