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/06/27 22:10:21
![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](/uploads/image/z/11714334-6-4.jpg?t=class+C+%7B+public+static+void+test%28String+s%29+%7B+if%28s+%3D%3D+null+%7C+s.length%28%29+%3D%3D+0%29+%7B+System.out.println%28class+C+%7Bpublic+static+void+test%28String+s%29+%7Bif%28s+%3D%3D+null+%7C+s.length%28%29+%3D%3D+0%29+%7BSystem.out.println%28%E2%80%9CString+is+null%E2%80%9D%29%3B%7D+else+%7BSystem.out.println%28%E2%80%9CStr)
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)此处