题目如下:
class NULL{
public static void haha() {
System.out.println("haha");
}
public static void main(String[] args) {
((NULL)null).haha();
}
}
以上程序能不能正常输出?
答案是可以。
将无类型的null转型为NULL类型,期望调用static haha方法,实际上这个方法和对象没有关系。
会产生一个警告,建议在类上调用static方法。