本帖最后由 张龙欢 于 2013-5-24 20:30 编辑
执行ListTest.main的结果是什么?class Data { int val;
int getVal() {
return val;
}
void setVal(int val) {
this.val = val;
}
}
public class ListTest {
public static void main(String args []) {
Data data = new Data();
ArrayList list = new ArrayList();
for (int i = 100; i < 103; i++) {
data.setVal(i);
list.add(data);
}
int j = 0;
while (j < list.size()) {
Data tmp = (Data) list.get(j);
System.out.println("list(" + j + ") = " + tmp.getVal());
j++;
}
}
} |