title: Singleton between many classes?
body: <p>I've got quite disturbing problem with singleton in my project.
  I created a class called Singleton (how creative) with a variable String name;</p>
  
  <p>Then I created another class called Player where I take a name of user.</p>
  
  <p>And main class where I want to save the data kept in Singleton.</p>
  
  <p>The problem is, it saves name of the user only if I take it in main class..it seems not to work in other classes. </p>
  
  <p>What is the reason ? How to fix it?
  Thanks for any advice :)</p>
  
  <p>Here's my singleton class:</p>
  
  <pre><code>private String name;
  
      public void setName(String name) {
         this.name = name;
      }
  
      public String getName( ) {
          return 
          this.name;
      }
  
      private static Singleton instance = null;
      protected Singleton() {
      }
  
      public static Singleton getInstance() {
          if(instance == null) 
          {
              instance = new Singleton();
          }
          return instance;
      }
  </code></pre>
  
  <p>This is a class where I take a name of a user:</p>
  
  <pre><code>    public class NewMain {
  
          public NewMain() {
              String u_name="agrfd";
              Singleton.getInstance().setName(u_name); 
          }
      }
  </code></pre>
  
  <p>And here is main class where I would like to save all data from Singleton (here I just try to print it to make sure it works):</p>
  
  <pre><code>public class NewMain1 {
  
  
  public static void main(String[] args) {
      Singleton singleton = new Singleton();
      System.out.println(singleton.getInstance().getName());
  
  
  }
  }
  </code></pre>