java:No enclosing instance of type Classname is accessible. Must qualify the allocation

来源:互联网 发布:手机设计装修软件 编辑:程序博客网 时间:2024/05/22 12:09

java编译错误:

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


原因:

成员内部类创建之前,必须先创建外部类。

形如:

public class outclass{

public class innerclass{

}

}


想要使用类innerclass,必须先创建外部类。

方法:

outclass out=new outclass();

out.innerclass inner=out.new innerclass();


1 0
原创粉丝点击