title: Swing objects declared as variable references or returned from methods?
body: <p>What are the differences between creating a Swing object as a variable reference or from being returned from a method? Which way is preferred?</p>
  
  <p>For example:</p>
  
  <pre><code>JButton button = new JButton(){}
  button.setText("Click Here");
  </code></pre>
  
  <p>Compared to:</p>
  
  <pre><code>public JButton Button(){
      JButton button = new JButton();
      button.setText("Select Folder");
      return button;
  }
  </code></pre>