【shuzu】...Dogdog=newDog();然后报错.Noenclosinginstanceoftypeshuzuis...

发布时间:2021-03-24 14:34:08

java:简单的实例化一个类,Dog dog=new Dog();然后报错.No enclosing instance of type shuzu is accessible.Must qualify the allocation with an enclosing instance of type shuzu (e.g.x.new A() where x is an instance of shuzu).

网友回答

【答案】 在Java中,类中的静态方法不能直接调用动态方法.只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法.解决办法是将public class改为public static class.
以上问题属网友观点,不代表本站立场,仅供参考!