class C { public static void test(String s) { if(s == null | s.length() == 0) { System.out.println(class C {public static void test(String s) {if(s == null | s.length() == 0) {System.out.println(“String is null”);} else {System.out.println(“Str
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 21:39:32
class C { public static void test(String s) { if(s == null | s.length() == 0) { System.out.println(class C {public static void test(String s) {if(s == null | s.length() == 0) {System.out.println(“String is null”);} else {System.out.println(“Str
class C { public static void test(String s) { if(s == null | s.length() == 0) { System.out.println(
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(class C {public static void test(String s) {if(s == null | s.length() == 0) {System.out.println(“String is null”);} else {System.out.println(“Str
D 会有异常.public static void test(String s)此处需要一个String类型的参数,而test(null)调用的时候传的参数是null,null是没有类型的!这样s是空的没有指向任何对象,所料无误应该报null pointer exception就在public static void test(String s)此处