编译和运行下面这段Java代码后,控制台输出的结果是?

} static int x, y;//本类属性,x,y默认为0 public static void main(String args[]) { x--;// 本类属性x-- this.x=-1 myMethod();System.out.println(x + y + ++x);//x = this.x = 1 ,y = 0, ++x = 2 //打印结果为 3 x + y + ++x = 1+0+2 = 3 ...
编译和运行下面这段Java代码后,控制台输出的结果是?
选D ,打印结果为3
public class Test {
static {
int x = 5;//形参x 赋值为5,没有调用
}
static int x, y;//本类属性,x,y默认为0

public static void main(String args[]) {
x--;// 本类属性x-- this.x=-1
myMethod();
System.out.println(x + y + ++x);//x = this.x = 1 ,y = 0, ++x = 2
//打印结果为 3 x + y + ++x = 1+0+2 = 3
}

public static void myMethod() {
y = x++ + ++x;
// x++ = -1 , this.x = 0
// ++x = 1 , this.x = 1
//y = -1 + 1 = 0
}
}2011-06-05
我在我电脑上运行了。答案是第四个 出现了个三

2011-06-05
ls正解。。。2011-06-05
mengvlog 阅读 7 次 更新于 2025-07-20 03:05:58 我来答关注问题0
檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部