Skip to content

Instantly share code, notes, and snippets.

@NearLinHere
Created June 17, 2015 07:41
Show Gist options
  • Save NearLinHere/30172bc22e503c15f412 to your computer and use it in GitHub Desktop.
Save NearLinHere/30172bc22e503c15f412 to your computer and use it in GitHub Desktop.
pkujava_ch5_TestInnerClass.java
class TestInnerClass{
public static void main( String[] args ){
Parcel p = new Parcel();
p.testShip();
Parcel.Contents c = p.new Contents(33);
Parcel.Destination d = p.new Destination( "Hawii" );
p.setProperty( c, d );
p.ship();
}
}
class Parcel {
private Contents c;
private Destination d;
class Contents {
private int i;
Contents( int i ){ this.i = i; }
int value() { return i; }
}
class Destination {
private String label;
Destination(String whereTo) {label = whereTo;}
String readLabel() { return label; }
}
void setProperty( Contents c, Destination d ){
this.c =c; this.d = d;
}
void ship(){
System.out.println( "move "+ c.value() +" to "+ d.readLabel() );
}
public void testShip() {
c = new Contents(22);
d = new Destination("Beijing");
ship();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment