public class Static{
static {
int x = 5;
}
static int x,y;
public static void main(String args[]){
x-- ;
myMethod();
System.out.println(x + y + ++x);
}
public static void myMethod(){
y = x+++++x;
}
}
主要是y = x+++++x;比较麻烦,执行这条语句之前x=-1
y = x+++++x => y = (x++) + (++x) => y = -1 + (++x)//x = 0
=> y = -1 + 1 //x = 1 => y = 0
所以x + y + ++x的结果为3