您的位置:首页 > 其它

出现No enclosing instance of type Exp is accessible. Must qualify the allocation with an enclosing ins

2016-09-22 11:10 711 查看
在进行实现接口的时候出现错误:No enclosing instance of type Exp is accessible. Must qualify the allocation with an enclosing instance of type Exp (e.g. x.new A() where x is an instance of Exp).如何处理。汉译:为没有可访问的内部类Exp的实例,必须分配一个合适的内部类Exp的实例(如x.new A(),x必须是Exp的实例。)Exp内部类是动态的,也就是开头以public
class开头。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。

方法一:在不做其他变动的情况下,最简单的解决办法是将public class改为public static class。

方法二:在Exp类外进行定义。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: