黑马程序员技术交流社区
标题:
测试题
[打印本页]
作者:
渴望学习
时间:
2014-7-26 20:10
标题:
测试题
29.下列哪些代码可以顺利通过编译和运行? ( )
A.Integer i = new Integer('A');
B.Integer i = new Integer("7");
C.Character c = new Character("A");
D.Boolean b = new Boolean(null);
E.Integer i = new Integer("0x10");
作者:
痞子、蔚
时间:
2014-7-26 22:24
ABD。。。。。。。。。。。。。。。。。。。
作者:
conglin1991
时间:
2014-7-26 22:34
ab?。。。。。。。。。
作者:
star5603
时间:
2014-7-26 22:57
痞子、蔚 发表于 2014-7-26 22:24
ABD。。。。。。。。。。。。。。。。。。。
A和D会对?
作者:
icris
时间:
2014-7-27 00:41
star5603 发表于 2014-7-26 22:57
A和D会对?
A是单引号,传入char,得结果65
D就要上源码了…
public Boolean(boolean value) {
this.value = value;
}
public Boolean(String s) {
this(parseBoolean(s));
}
public static boolean parseBoolean(String s) {
return ((s != null) && s.equalsIgnoreCase("true"));
}
复制代码
null不能是boolean只能是String,Boolean(null)调用this(parseBoolean(s)),parseBoolean(null)返回false,则等效于Boolean(false),得到false
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2