-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParcel2.java
More file actions
41 lines (35 loc) · 898 Bytes
/
Parcel2.java
File metadata and controls
41 lines (35 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// innerclasses/Parcel2.java
// Returning a reference to an inner class
package com.innerclasses10;
public class Parcel2 {
class Contents {
private int i = 11;
public int value() { return i; }
}
public Contents contents() {
return new Contents();
}
class Destination {
private String label;
Destination(String whereTo) {
label = whereTo;
}
public String readlabel() { return label; }
}
public Destination destination(String whereTo) {
return new Destination(whereTo);
}
public void ship(String dest) {
Contents c = contents();
Destination d = destination(dest);
System.out.println(d.readlabel());
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Parcel2 p = new Parcel2();
p.ship("Tasmania");
Parcel2 q = new Parcel2();
Parcel2.Contents c = q.contents();
Parcel2.Destination d = q.destination("Borneo");
}
}