买了Thinking In Java 这本书,应该有光盘啊.里面都给你做出来了,
那个程序多标准啊.怎么还要做啊...或者去www.Bruce.com下嘛
那个程序多标准啊.怎么还要做啊...或者去www.Bruce.com下嘛
解决方案 »
- 50分求教 java菜鸟求救高手推荐一本java入门的好书 最最基础的 没有语言基础
- 急!!!奇怪的jsp与mysql问题
- 如何读取EXCEL中的内容
- 如何用类似g.drawline()的方法画一条比较粗的线?
- 请教高手:JTable中默认的是不是都是可编辑的?为什么我的是不可编辑呢?
- JDialog和JFrame的区别,分别在什么场合用它们,在线给分
- 如何安装和使用JAI?
- 简单问题!!!100分!!!
- 我想学习JAVA,谁能推荐我一本好的入门教材?
- Applet是否可以调用服务器端的bean,或者是Frame
- *****求java日历程序*****在线等,
- 怎么得到一个JAVA程序有多少个线程在运行中?
void u1(); void u2(); void u3();
}
class A11 {
int i = 1; void incr() {
i++;
}
U getAU() {
return new U() {
public void u1() {
System.out.println("u1()");
}
public void u2() {
System.out.println("u2()");
} public void u3() {
System.out.println(i);
incr();
}
};
}
}
class E27_B {
U[] us;
int next = 0; E27_B(int size) {
us = new U[size];
} void addAU(U u) {
if (next < us.length) {
us[next] = u;
next++;
}
} void removeAU(int number) {
if (number >= 0 && number < us.length) {
us[number] = null;
}
} void callAll() {
for (int i = 0; i < us.length; i++) {
us[i].u1();
us[i].u2();
us[i].u3();
}
} public static void main(String[] args) {
A11 a11 = new A11();
E27_B b = new E27_B(10); for (int i = 0; i < 10; i++) {
b.addAU(a11.getAU());
}
b.callAll();
System.out.println(a11.i);
b.us[0].u3();
System.out.println(a11.i);
b.removeAU(0);
System.out.println(b.us[0]);
System.out.println(b.us[1]);
}
}
在class All的getAU()函数中,返回一个匿名inner class实现interface U.
在class E27_B中addAU(U u)即题目的第一个函数;void removeAU(int number) 即题目的第二个函数;void callAll() 即题目的第三个函数。
main中的b.addAU(a11.getAU());即回调all对象。