调用内部类里,在静态类中调用动态方法的问题

在编译写书上一个例子时,添加一个内部类时,出现了问题:“No enclosing instance of type GameSaverTest is accessible. Must qualify the allocation with an enclosing instance of type GameSaverTest (e.g. x.new A() where x is an instance of GameSaverTest).”其中GameSaverTest指代那个内部类。

public static void main (String[] args),而GameSaverTest这个内部类是动态的,也就是开头以public class开头。在Java中,类中的静态方法不能直接调用动态方法。将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。

原文地址:https://www.cnblogs.com/dengyt/p/6635311.html