What will happen when you attempt to compile and run the following code?
public class Test{
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;
}
}
答案是3
static代码块里的x是局部变量,y=x+++++x中x++是下次使用x时+1,++x时本次使用x就加1。