今天遇到这样一个面试题:
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
最终确认了我的猜想,
终结:遇到问题多动手,实践检验真理