您的位置:首页 > 其它

No enclosing instance of type Monster is accessible. Must qualify the allocation with an enclosing i

2012-07-14 19:55 453 查看
错误提示:No enclosing instance of type Monster is accessible. Must qualify the allocation with an enclosing instance of type Monster (e.g. x.new A() where x is an instance of Monster).

于是百度谷歌了一下相关资料。原来我写的内部类是动态的,也就是开头以public class开头。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。所以解决办法是将public class改为public static class.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐