日期:2014-05-20 浏览次数:20714 次
public class Parcel2 {
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 Destination to(String s) {
return new Destination(s);
}
public Contents contents() {
return new Contents();
}
public void ship(String dest) {//在非静态方法中只需要写出内部类名便可指定其类型
Contents c = contents();
Destination d = to(dest);
System.out.println(d.readLabel());
}
public static void main(String[] args) {
Parcel2 p = new Parcel2();
p.ship("Tasmania");
Parcel2 q = new Parcel2();
Parcel2.Contents c = q.contents();
Parcel2.Destination d = q.to("Borneo");
}
}