No enclosing instance of type 错误的解决方法

 今天做练习的时候碰到的小问题:

 

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

这次练习中,我写的两个内部类都是动态的,报错的原因应该是因为由静态的main方法无法去调用动态的类

在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,才可以再静态类中调用带类的成员变量和成员方法。

解决方案:在类名前加上static 把内部动态类改成静态类

posted @ 2019-03-13 18:03  FerrisXu  阅读(1201)  评论(0编辑  收藏  举报