class C {
public static void test(String s) {
if(s == null | s.length() == 0) {
System.out.println(“String is null”);
} else {
System.out.println(“String is not null”);
}
}
public static void main(String[] args) {
test(null);
}
}
则输出为
(A)String is null
(B)String is not null
(C)编译错误
(D)运行时异常
class C { public static void test(String s) { if(s == null | s.length() == 0) { System.out.println(
答案:3 悬赏:30
解决时间 2021-04-08 17:30
- 提问者网友:清茶柒夏
- 2021-04-07 17:15
最佳答案
- 二级知识专家网友:嗷呜我不好爱
- 2021-04-07 17:24
D 会有异常。public static void test(String s)此处需要一个String类型的参数,而test(null)调用的时候传的参数是null,null是没有类型的!这样s是空的没有指向任何对象,所料无误应该报null pointer exception就在public static void test(String s)此处
全部回答
- 1楼网友:堕落奶泡
- 2021-04-07 18:52
编译错误。 错误1.s"="+s ---> "s=" + s; 错误2.因为s没有被初始化,因此编译通不过。 这个he string str = null;不同 希望对你有所帮助
- 2楼网友:短发女王川岛琦
- 2021-04-07 18:27
D:运行时异常, if(s == null | s.length() == 0) {
当执行到此行代码时,会出现java.lang.NullPointerException,因为两个条件如果用 | 来连接的话,那么即使第一个条件满足了,第二个条件同样会执行,所以传的参数为null时,运行到 s.length() == 0就会抛出空指向异常。以上仅供参考,希望对您有所帮助。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯