Java内部类问题,
interface Destination
{
String readLabel();
}
class Parcel
{
public Destination dest(String s)
{
class PDestination implements Destination
{
private String label1;
private PDestination(String whereTo)
{
label1 = whereTo;
}
public String readLabel()
{
return label1;
}
}
return new PDestination(s);
}
public static void main(String[] args)
{
Parcel p = new Parcel();
Destination d = p.dest("Tanizania");
System.out.println(d.readLabel());
}
}
运行结果
Tanizania:
疑惑:
不是类的构造函数申明了private????怎么还可以生成对象??
具体见thinking in java(2E) P264