2015-04-20 15:36:01 -07:00
|
|
|
//: innerclasses/Parcel11.java
|
|
|
|
// Nested classes (static inner classes).
|
|
|
|
|
|
|
|
public class Parcel11 {
|
|
|
|
private static class ParcelContents implements Contents {
|
|
|
|
private int i = 11;
|
2015-05-05 11:20:13 -07:00
|
|
|
@Override
|
2015-04-20 15:36:01 -07:00
|
|
|
public int value() { return i; }
|
|
|
|
}
|
|
|
|
protected static class ParcelDestination
|
|
|
|
implements Destination {
|
|
|
|
private String label;
|
|
|
|
private ParcelDestination(String whereTo) {
|
|
|
|
label = whereTo;
|
|
|
|
}
|
2015-05-05 11:20:13 -07:00
|
|
|
@Override
|
2015-05-18 23:05:20 -07:00
|
|
|
public String readLabel() { return label; }
|
2015-04-20 15:36:01 -07:00
|
|
|
// Nested classes can contain other static elements:
|
|
|
|
public static void f() {}
|
|
|
|
static int x = 10;
|
|
|
|
static class AnotherLevel {
|
|
|
|
public static void f() {}
|
|
|
|
static int x = 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static Destination destination(String s) {
|
|
|
|
return new ParcelDestination(s);
|
|
|
|
}
|
|
|
|
public static Contents contents() {
|
|
|
|
return new ParcelContents();
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Contents c = contents();
|
|
|
|
Destination d = destination("Tasmania");
|
|
|
|
}
|
|
|
|
} ///:~
|