黑马程序员技术交流社区

标题: 测试自增和自减 [打印本页]

作者: user_lqb    时间: 2016-4-1 19:10
标题: 测试自增和自减
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;
}
}

A   compiletime error
  
B   prints:1
  
C   prints:2
  
D prints:3
  
E   prints:7
  
prints:8
  




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2