Error:
No enclosing instance of type *** is accessible. Must qualify the allocation with an enclosing instance of type *** (e.g. x.new A() where x is an instance of Test).
[***代表类名]
public class Test
{
public static void main(String[] args)
{
/**第一句没问题*/
A a = new A();
/**第二句错误信息:
* No enclosing instance of type Test is accessible.
* 【没有Test类型可以被访问】
* Must qualify the allocation with an enclosing instance of type Test
* (e.g. x.new A() where x is an instance of Test).
* 【就是说Test的实例不存在,所以Test类的内部类是更是无从谈起】
* 【而A类不同A和main方法一样都在栈中可以被访问到(并不需要首先实例化Test类)】
* */
B b = new B();
}
static class A
{
public A()
{
System.out.println("我是静态内部类的空参数构造函数");
}
}
class B
{
public B()
{
System.out.println("我是非静态内部类的空参数构造函数");
}
}
}
参考:http://baike.baidu.com/link?url=wj-ZWDuDFKakckKytRRARWqNKpDr5LzHOCgKzxWl4WHBV4RLxOyGpSOydMmWPK1myEJkEbu_XkCZiuns617aYa点击打开链接