package com.csc.innerclasstest;
/**
*
* @author csc
*
*/
//外部类
public class OuterClass {
/**
* @param args
*/
public static void main(String[] args) {
InnerClass innerClass = new InnerClass();
innerClass.say();
System.out.println("I am in OuterClass!");
}
//定义一个内部类
private class InnerClass{
private void say() {
System.out.println("I am in InnerClass!");
}
}
}
上面的代码的第16行将会报出“No enclosing instance of type OuterClass is accessible. Must qualify the allocation with an enclosing instance of type OuterClass (e.g. x.new A() where x is an instance of OuterClass).”这样的编译错误。
怎么处理? |