我已经创建了2个Java文件。1. helloWorld.java 2.文件夹p / node.java中helloWorld.java文件夹包含主要功能import p.node; import java.util.ArrayList; import java.util.List; public class helloWorld { public static void main(String[] args) { List<node> list = new ArrayList<node>(); //created list of object node list.add(new node('a')); list.add(new node('b')); list.add(new node('c')); list.add(new node('g')); list.add(new node('k')); list.add(new node('o')); System.out.println(list.get(2).val); }}2. node.javapackage p;public class node { public static char val; public boolean busy = true; public node(char val) { this.val=val; }}预期输出c实际输出o请帮助我,我是java的新手...预先感谢!
2 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
您已声明val为static和static成员为created only once
static从node类中删除声明
package p;
public class node {
public char val;
public boolean busy = true;
public node(char val) {
this.val=val;
}
}
添加回答
举报
0/150
提交
取消