String a;System.out.println("1:"+a);

来源:互联网 发布:打鱼平台游戏源码 编辑:程序博客网 时间:2024/06/05 23:46

今天遇到这样一个面试题:

public static void main(String[] args) {

String a;
System.out.println("1"+a);
a="helloword";
System.out.println("2"+a);

}

最后打印的结果是:

A: 1:

2:helloword

B:1:null

2:  helloword

C:1:NULL

2:  helloword

D:运行异常

我选D,本来不太相信自己的答案,就去写了一下运行了一下:

结果是:Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The local variable a may not have been initialized

最终确认了我的猜想,

终结:遇到问题多动手,实践检验真理


原创粉丝点击