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/18 02:58:58
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)此处