/Users/lyon/j4p/src/bookExamples/ch12Nested/inner/Inner.java
|
1 package bookExamples.ch12Nested.inner;
2
3 class Inner {
4 public static void main(String args[]) {
5 Bank b = new Bank();
6 System.out.println(b.getCustomer().getName());
7 }
8 }
9
10 // run using:
11 // examples.inner.Job
12
13 abstract class Job {
14 static Job j = new EdsJob();
15
16 Thread t = null;
17
18 Job(Runnable r) {
19 t = new Thread(r);
20 t.start();
21 }
22
23 abstract void killMe();
24
25 public static void main(String args[]) {
26 j.killMe();
27 }
28
29 private static class EdsJob extends Job {
30 public EdsJob() {
31 super(new Runnable() {
32 public void run() {
33 System.out.println("Hidee hoe!");
34 }
35 });
36 }
37
38 public void killMe() {
39 System.out.println("test");
40 }
41 }
42 }
43
44 class Bank {
45 Customer getCustomer() {
46 return new Customer() {
47 String getName() {
48 return "Frank";
49 }
50 };
51 }
52 }
53
54 abstract class Customer {
55 abstract String getName();
56 }
57
58 interface MetricFcn {
59 double metric2English(double d);
60
61 double english2Metric(double d);
62 }
63
64 class Meters2Yards {
65 static MetricFcn meters2Yards = new MetricFcn() {
66 public double metric2English(double d) {
67 return d / 1.1;
68 }
69
70 public double english2Metric(double d) {
71 return d * 1.1;
72 }
73 };
74
75 public static void main(String args[]) {
76 System.out.println("10 meters =" +
77 meters2Yards.metric2English(10) + " yards");
78 }
79 }
80
81 interface Command {
82 public void run();
83 }
84
85 class Commando {
86 Command getCommand() {
87 return new Command() {
88 public void run() {
89 System.out.println("hello world!");
90 }
91 };
92 }
93
94 public void doit() {
95 getCommand().run();
96 }
97
98 public static void main(String args[]) {
99 Commando c = new Commando();
100 c.doit();
101 }
102 }
103
104 class A {
105 static int a = 10;
106
107 public static void main(String args[]) {
108 System.out.println("a=" + a);
109 }
110 }
111
112 class Shadow {
113 int a = 10;
114 int b = 20;
115
116 void setA(int a) {
117 this.a = a;
118 }
119
120 void setB(int _b) {
121 b = _b;
122 }
123 }
124
125