Java中报No enclosing instance of type test is accessible. Must qualify the allocation with an enclosin
我的代码如下
第十行报错
No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing instance of type test (e.g. x.new A() where x is an instance of test).
译文是:没有封闭的实例类型测试是可访问的。必须有资格分配一个封闭测试类型的实例(例如,x。新()其中x是一个实例的测试)。
原因是:内部类H是动态的,主程序是静态的,在java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法
然后我将public class H 改成public static class H就没有报错了