请写出如下代码的运行结果:
主要考察自增运算
代码语言:javascript复制public class Test1 {
static int x, y;
static {
x = 5;
}
public static void main(String[] args) {
x --;
someMethod();
System.out.println(x y x);
}
private static void someMethod() {
y = x x;
}
}
逐条分析
代码语言:javascript复制public class Test1 {
static int x, y;
static {
x = 5;
}
public static void main(String[] args) {
x --; // x = 4
someMethod();
System.out.println(x y x); // 6 10 (6 1) = 23
}
private static void someMethod() {
y = x x;
// x = (4 1) 1 = 6
// y = (4 (4 1)) 1 = 10
}
}
结果为23