java内部类使用例子

写道
public class OuterClass{
private int varOuter=0;
public OuterClass(){}
public void callOut(){
final int varouter2=0; //此处需为final类型,内部类中使用局部变量需为final类型,局部变量不能有public等关键字标识
class InnerClass{
private int varInnerOuter=0;
public InnerClass(){}
public void print()
{
System.out.println("outer"+varOuter);
System.out.println("outer2"+varouter2);
System.out.println("inner"+varInnerOuter);
}
}
InnerClass inner=new InnerClass();
inner.print();
}

public static void main(String args[]){
OuterClass outer=new OuterClass();
outer.callOut();
}
}

 

你可能感兴趣的:(java)