我有点麻烦了解下面的代码的输出。有人可以解释确切的步骤,以便我可以更好地了解发生了什么?有人可以请解释输出java
public class Foo {
private static int id = 0 ;
private int myId ;
public Foo() {
myId = id ;
++id ;
}
public int getMyId() {
return myId ;
}
public static void main(String[] args) {
Foo f1 = new Foo();
Foo f2 = new Foo();
System.out.println(f1.getMyId());
System.out.println(f2.getMyId());
System.out.println(id);
}
}
你能解释一下为什么输出等于:
0
1
2
你有没有试过走通路你自己呢?如果是这样,哪个确切的部分是你感到困惑? – resueman
你可以请[编辑]你的问题,并修复你的代码的indetion?这是非常难以阅读。 – 2016-03-04 14:47:39