您的位置:首页 > 其它

No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where x is an instance of Demo).

2017-04-21 09:19 537 查看
No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where
x is an instance of Demo).


在练习一Demo时,遇到上面的编译时错误



原因:main是Test类的static方法,按照常理它只能访问Test类中static资源,而class A是非static所以报错了。

解决方法一:给class F添加static属性。



解决方法二: 没有必要把F放在Demo中做内部类,将它移到Demo外部地方定义。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐