publicclass TestClass {
privatestatic void testMethod(){
System.out.println("testMethod");
}
publicstatic void main(String[] args) {
((TestClass)null).testMethod();
}
}
这个是可以正常运行的,如果把static去掉就会空指针异常
1: null可以转化为任何类型
2: private 只是权限声明
2:static静态关键字 仅仅意味着可以不用实例化这个类
通过类名.方法名就可以访问
当然也可以通过实例化类的对象后 通过对象.方法名
但是不能通过this关键字,因为this是指本实例中的方法被static声明的方法属于类的方法
题目来源:牛客网http://www.nowcoder.com/questionTerminal/e252668ee94947bea07edd7300340115