I came across the code of guessgame. There is a code snippet where three player objects are initialized the following way:
public class guessgame{
Player p1;
Player p2;
Player p3;
public void startGame() {
p1 = new Player();
p2 = new Player();
p3 = new Player();
...
}
...
}
The same worked when I declared and initiated it the following way as well.
public class GuessGame {
Player p1 = new Player();
Player p2 = new Player();
Player p3 = new Player();
public void startGame(){
...
}
...
}
Is there a difference between the two? In the first example, why was the three instance variables declared outside the startgame() method, and does it really matter internally?
GuessGameclass, the first initialises them whenstartGame()is run.