运行下面程序,请选择输出结果
public class x(
private static int a
pubilc static void main(String[ ] args) {
modify(a)
System. out.println(a);
}
public static void modify(int a) {
a++;
}
(a) 0
(b) 1
(0) 2
(d) 3
考点: 考察求职者对于类的静态变量的理解。
出现频率: ★★★★
【面试题解析】类的静态变量a在modify()方法中并没有被改变,而是改变了modify() 方法的参数。(就近原则)如果将上述代码修改如下:
public class x(
private static int a;
pubilc static void main(String[ ] args) {
modify(a)
System. out.println(a);
}
public static void modify(int b) {
a++;
}
那么输出结果为1,但是面试题中静态变量a的值并没有改变,所以应该输出为0。
参考答案:(a)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有