Unable to access variable when declared in class. Working when declared in a function. Why?
<p>In the following code, <code>LinkedList</code> is a class for creating -obviously- Linked Lists and it has the method <code>insertFirst(..)</code> and <code>displayList()</code>.</p>

<p>I was trying to use this class to create a variable in another class --> FCFS class. Declaring it as a private variable in the class FCFS results in NullPointerException error at the lines: <code>process.insertFirst(..)</code> and <code>process.display()</code>. While when I declared it inside <code>work()</code> method it worked perfectly.</p>

<p>I just want to understand why this works:</p>

<pre><code>public class FCFS {   
    public void work(){
      LinkedList process = new LinkedList();  
      process.insertFirst(3);
      process.displayList(); 
    }     
}
</code></pre>

<p>while this doesn't:</p>

<pre><code>public class FCFS {
    private LinkedList process;

    public void work(){
        process.insertFirst(3); 
        process.displayList(); 
    }     
}
</code></pre>
