I am reposting my question.
There are 3 reference variables root1,root2,root3,they are included in a reference array (root[]={root1,root2,root3}).
I initialized the object for root[0],I hope root[0] refers to root1 ,So i expect root1.data and root[0].data to access the same value.But i am not able to access using root1.data whereas i am able to access it using root[0].data.
public class testing
{
static Node root1,root2,root3;
public static void main(String[] args)
{
Node root[]={root1,root2,root3};
root[0]=new Node(2,null);
System.out.println("root[0]="+root[0].data);//It is working properly
System.out.println("root1="+root1.data);//It is not working properly
}
public static class Node
{
int data;
Node next;
Node(int data,Node next)
{
this.next=next;
this.data=data;
}
}
}