【发布时间】:2017-02-16 16:11:38
【问题描述】:
我正在重新发布我的问题。
有3个引用变量root1,root2,root3,它们包含在一个引用数组中(root[]={root1,root2,root3})。
我为 root[0] 初始化了对象,我希望 root[0] 引用 root1,所以我希望 root1.data 和 root[0].data 访问相同的值。但是我无法使用root1.data 而我可以使用 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;
}
}
}
【问题讨论】:
-
为什么需要所有节点都是静态的?尝试不使用静态修饰符但使用主要方法
-
你为什么要转发你的问题?改为编辑您的原始问题。我投票决定将此问题作为原始问题的副本结束。
-
请客气。