您的位置:首页 > 其它

No enclosing instance of type xxx is accessible

2015-07-25 11:36 288 查看
   No enclosing instance of type test5 is accessible. Must qualify the allocation with an enclosing instance of type test5 (e.g. x.new A() where x is an instance of test5).在一个类里面的main函数,经常会写一些测试代码。在调用这个类里面的内部类的时候,出现不能初始化内部类的对象实例。发现两种解决方法:1、把内部类换成静态类2、直接把在main函数初始化的内部类,挪到类里面的一个方法里面即可。原先出问题的代码
  public class W extends Wifi<String>{@Overridepublic String getNet(){// TODO Auto-generated method stubreturn "WWWW";}}public static void main(String[] args){// TODO Auto-generated method stubW ww = new W();ww.net();ww.ondo();System.out.println(ww.getNet());}
修改之后:
 public class W extends Wifi<String>{@Overridepublic String getNet(){// TODO Auto-generated method stubreturn "WWWW";}}public void testW(){W ww = new W();ww.net();ww.ondo();System.out.println(ww.getNet());}public static void main(String[] args){// TODO Auto-generated method stubtest5 test5 = new test5();test5.testW();}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: