您当前的位置: 首页 > 

大前端之旅

暂无认证

  • 1浏览

    0关注

    403博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

No enclosing instance of type JDStudent is acAcessible. Must qualify the allocation with an enclosin

大前端之旅 发布时间:2020-01-02 18:35:18 ,浏览量:1

在这里插入图片描述 No enclosing instance of type JDStudent is acAcessible. Must qualify the allocation with an enclosing instance of type JDStudent (e.g. x.new A() where x is an instance of JDStudent). 在这里插入图片描述 E(e.g. x.new A() where x is an instance of E). E指代我写的那个内部类。 根据提示,没有可访问的内部类E的实例,必须分配一个合适的内部类E的实例(如x.new A(),x必须是E的实例。)看着这句提示,我就纳闷了,我已经用new实例化了这个类,为什么还不行呢。 于是百度谷歌了一下相关资料。原来我写的内部类是动态的,也就是开头以public class开头。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。所以在不做其他变动的情况下,最简单的解决办法是将public class改为public static class. 今天记录下来

关注
打赏
1660524863
查看更多评论
立即登录/注册

微信扫码登录

0.0350s