Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
来源:互联网 发布:淘宝联盟电脑版和手机 编辑:程序博客网 时间:2024/06/06 09:08
问题:No enclosing instance of type Three is accessible. Must qualify the allocation with an enclosing instance of type Three (e.g. x.new A() where x is an instance of Three).
代码:public class Three {
public static void main(String[] args) {
Person person=new Person();
System.out.println(person.name);
}
public class Person{
public String name="Person";
int age=0;
}
public class Child extends Person{
public String grade;
}
}
原因:内部类是动态的,也就是开头以public class开头。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。所以在不做其他变动的情况下,最简单的解决办法是将public class改为public static class.
0 0
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Hive 启动报错 ClassNotFoundException: org.apache.hadoop.hive.service.HiveServer
- 易语言 特征码的8种修改方法
- Linux三大共享文件的方法
- eclipse启动tomcat后localhost:8080无法访问问题
- spring security 一个验证码登录例子
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- 扒一扒网页设计里的浮动 属性
- [转载]Java面试基础概念总结
- session与cookie的区别
- 【Android】无法发送短信的问题
- 重装系统提示“Windows安装无法继续”
- 素数筛法
- 易语言 修改IE协议头模拟手机浏览网页
- 随笔:我为什么要写博客?