title: Different ways to initialize variables in Java
body: <p>I came across the code of <code>guessgame</code>. There is a code snippet where three player objects are initialized the following way:</p>
  
  <pre><code>public class guessgame{
      Player p1;
      Player p2;
      Player p3;
      public void startGame() {
          p1 = new Player();
          p2 = new Player();
          p3 = new Player();
      ...
      }
      ...
  }
  </code></pre>
  
  <p>The same worked when I declared and initiated it the following way as well.</p>
  
  <pre><code>public class GuessGame {
      Player p1 = new Player();
      Player p2 = new Player();
      Player p3 = new Player();
      public void startGame(){
          ...
      }
      ...
  }
  </code></pre>
  
  <p>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?</p>