What will happen when you attempt to compile and run the following code?
2019独角兽企业重金招聘Python工程师标准>>>
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
转载于//my.oschina.net/u/3847203/blog/3015476
还没有评论,来说两句吧...