No enclosing instance of type StudentTest is accessible. Must qualify the allocation with an enclosi
No enclosing instance of type StudentTest is accessible
原因:主程序是静态,局部类是动态的,类中的静态方法不能直接调用动态方法;
解决方案:1、可以将局部类改为静态类
2、将局部类移除静态类中
注:静态成员是在JVM的ClassLoader加载类的时候初始化的,而非静态成员是在创建对象,也就是new操作的时候才初始化的。类加载的时候初始化static的成员,此时static 已经分配内存空间,所以可以...
原创
2021-09-10 11:31:20 ·
767 阅读 ·
0 评论