java----内部类

public class Parcell
{
class Contents
{
private int i=11;
public int value()
{
return i;
}
}
class Destination
{
private String label;
Destination(String whereTo)
{
label=whereTo;
}
String readLabel()
{
return label;
}
}
public void ship(String dest)
{
Contents c=new Contents();
Destination d=new Destination(dest);
System.out.println(d.readLabel());
}
public static void main(String[] args)
{
Parcell p=new Parcell();
p.ship("Tasmania");
}

}
/*
* 将Contents,Destination,类置于Parcell类中。
*
*
* 当我们在ship()方法里使用内部类的时候,与使用普通类没什么不同
*
* -----摘自《Java编程思想》
* */
*/

原文地址:https://www.cnblogs.com/fanzhengzheng/p/7496582.html