title: How to access static variable from another class?
body: <p>I'm trying to access the variable "name" in the Client class from the Server class. This is what I tried to do, but when I print it, it says it's null (?). How can I fix this? Thanks in advance...</p>
  
  <p>Client class</p>
  
  <pre><code>class Client {
      static Socket socket;
      static String name;
  
      public static void main(String[] args) throws Exception {
  
          String hostname = "";
          int port = 0;
  
          if (args.length == 3) {
              hostname = args[0];
              port = Integer.parseInt(args[1]);
              name = args[2];
              System.out.println("(" + hostname + ":" + port + ")");
          } else {
              hostname = "localhost";
              port = 3000;
              name = "default";
              System.out.println("Using all default arguments. (" + hostname + ":" + port + ")");
          }
  
          Client c = new Client(hostname, port);
          c.connect();
      }
  }
  </code></pre>
  
  <p>Server class</p>
  
  <pre><code>class Server {
      ServerSocket main;
      Helper helper;
  
      static class MailServer extends Thread {
          DataInputStream dataIn;
          DataOutputStream dataOut;
          int index;
          Helper helper;
          String name = Client.name; //&lt;--- HERE
      }
  }
  </code></pre>