r*****l 发帖数: 2859 | 1 1, 下面的code运行结果会怎么样? Assume you don't have java in handy to test
run it.
2, 如果面试被问到,怎么回答呢?
try {
char[] cs = {'a', 'b'};
String s = null;
s = s.copyValueOf(cs);
System.out.print(s);
} catch (NullPointerException e) {
System.exit(1);
} catch (Throwable e) {
System.exit(2);
}
Note: "copyValueOf" is a static method of String class.
1, prints out "ab"
2, exit with "1"
3, exit with "2" | g**e 发帖数: 6127 | 2 难道不是应该输出"ab"?
eclipse会报warning
【在 r*****l 的大作中提到】 : 1, 下面的code运行结果会怎么样? Assume you don't have java in handy to test : run it. : 2, 如果面试被问到,怎么回答呢? : try { : char[] cs = {'a', 'b'}; : String s = null; : s = s.copyValueOf(cs); : System.out.print(s); : } catch (NullPointerException e) { : System.exit(1);
| l*********s 发帖数: 5409 | |
|