有关下述Java代码描述正确的选项是____。
public class TestClass {
private static void testMethod(){
System.out.println("testMethod");
}
public static void main(String[] args) {
((TestClass)null).testMethod();
}
}
public class TestClass {
private static void testMethod(){
System.out.println("testMethod");
}
public static void main(String[] args) {
((TestClass)null).testMethod();
}
}
编译不通过
编译通过,运行异常,报NullPointerException
编译通过,运行异常,报IllegalArgumentException
编译通过,运行异常,报NoSuchMethodException
编译通过,运行异常,报Exception
运行正常,输出testMethod
方法是static静态方法,直接使用"类.方法"就行了,因为静态方法在对象创建前就存在了,他的使用不依赖对象是否被创建.
非静态的方法用"对象.方法"的方式,因为他在对象创建前不存在,必须依赖对象的创建后,才能使用