//注意++i/i++的不同,尽管i最终都增1
public class JavaTest1 {
static{
int x = 5;
}//此处x为局部变量,只在块内有作用
static int x, y;//默认初始值为0
public static void main(String[] args) {
x--;//x-1
TestMethod();
System.out.println(x+ y++ +x++);//1+0+1
System.out.println(x+" "+y);//2 1
}
public static void TestMethod(){
y =x++ + ++x ;//x++和++x都是表达式,x++返回x的值(-1)后加1,++x加1后返回值1,所以y为0
}
}
i++与++i返回时机不同
i++:
return = i;
i=i+1;
++i:
i=i+1;
return = i;