-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathParcel10.java
More file actions
27 lines (25 loc) · 772 Bytes
/
Parcel10.java
File metadata and controls
27 lines (25 loc) · 772 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
package thinkinginjava.innerclasses;
// Using "instance initialization" to perform
// construction on an anonymous inner class.
public class Parcel10 {
public Destination destination(final String dest, final float price) {
return new Destination() {
private int cost;
// Instance initialization for each object:
{
cost = Math.round(price);
if(cost > 100)
System.out.println("Over budget!");
}
private String label = dest;
public String readLabel() { return label + " " + cost; }
};
}
public static void main(String[] args) {
Parcel10 p = new Parcel10();
Destination d = p.destination("Tasmania", 101.395F);
System.out.println(d.readLabel());
}
} /* Output:
Over budget!
*///:~