I have following code
class Demo {
static int a = 0;
static int b = 1;
static {
a = ++b;
}
void gam(int x) {
a = a * x;
b = b * x;
}
}
class Test {
public static void main(String[] args) {
Demo d1 = new Demo();
Demo d2 = new Demo();
d1.a++;
d2.a--;
System.out.println(d1.a + " " + d1.b + " " + d2.a + " " + d2.b);
}
}
But I can't figure out why d1.a is 2. Shouldn't it be 3? Since a=++b makes it 2 and d1.a++ makes it 3?