package NowCoder;
class Test {
    public static void hello() {
        System.out.println("hello");
    }
}
public class MyApplication {
    public static void main(String[] args) {
      
        Test test=null;
        test.hello();
    }
}
结果
hello

 

解析:

静态方法是属于类的,与对象无关,只要是使用到了Test类,都会加载静态hello方法!

空指针必须是去引用堆对象才会有空指针,而这个hello是static类型的,人家static的方法本身就没有指针,所以当然不会有空指针。

引用类型  引用名=null,其实就是指该引用在堆中没有对应的对象,但是编译的时候还是能根据声明找到其所属的静态类型。


 
 

相关文章:

  • 2022-02-09
  • 2021-07-14
  • 2022-03-10
  • 2022-01-28
  • 2021-08-05
  • 2021-09-07
  • 2022-12-23
猜你喜欢
  • 2022-01-29
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案