regarding this keyword (java)
<p>I have a question regarding the output of the following program. The output is null. This is what I thought as well. Im thinking its because the methods called before display simply modify a copy of head and not head itself. Im assuming that I could get around this using a this.head= something right?</p>

<p>Heres the code:</p>

<pre><code>public class List {
    private Node head;
    public List (){
        int max=3;
        int i;
        head=null;
        Node aNode=new Node(0);
        for (i=0; i&lt;max; i++) {
            aNode.setNum(i);
            add (aNode);
            aNode.setNext(null);
            }
        }
    public void add(Node aNode) {
        Node temp;
        if(head==null)
            head=aNode;
        else {
            temp=head;
            while(temp.getNext()!=null)
                temp=temp.getNext();
            temp.setNext(aNode);
            }
        }
    public void display() {
        Node temp=head;
        while(temp!=null) {
            System.out.println(temp.getNext());
            temp=temp.getNext();
            }
        }
    }


public class Node {
    private int num;
    private Node next;
    public Node (int n) {num=n; next=null;}
    public int getNum() {return num;}
    public void setNum(int n) {num=n;}
    public void setNext(Node n) {next=n;}
    public Node getNext() {return next;}
    }

public class Driver {
    public static void main(String args[]) {
        List aList=new List();
        aList.display();
        }
}
</code></pre>
