I'm confused as to why the following code doesn't change the data of the Node a:
public class Node{Node next; int data;}
public static void change(Node a)
{
a = a.next;
}
public static void main(String [] args){
Node a = new Node();
Node b = new Node();
a.next = b;
a.data = 1;
b.next = null;
b.data = 2;
change(a);
System.out.print(a.data); //Still 1, why isn't it changed to 2?
}
Since Node is an object, isn't its reference passed by value to the method change? Which means any changes made to the passed in Node should actually change the node?