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;    //注意这个运算  ++x 已是x++ 的下一个指令了,所以,x 已经+1
 }
}
  • compiletime error
  • prints:1
  • prints:2
  • prints:3   (答案)
  • prints:7
  • prints:8
相关文章
相关标签/搜索