title: Accessing variable in Main method from other class
body: <p>I have two classes:</p>
  
  <pre><code>public class node {
    static LinkedList&lt;Integer&gt; nodes = new LinkedList&lt;Integer&gt;();
    public boolean visited;
  
    public static void Main (String args []) {
      System.out.println("Number of nodes in network");
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
  
      for (int i=1;i&lt;=n;i++){
        nodes.add(i);
      }
  
      System.out.println(nodes);
    }
  </code></pre>
  
  <p>and another class</p>
  
  <pre><code>public class AdjacencyList {
    private int n;
    private int density;
  </code></pre>
  
  <p>I want to access <code>int n</code> from <code>Main</code>method and assign its value to <code>private int n</code> in <code>AdjacencyList</code> class.  I tried <code>node.n</code> (class.variable) format in a method where I can assign values but its not working out. Can anybody please help me with this?</p>