动态绑定:是很重要的特性,它能使程序变得可扩展而不需要重编译已存代码为什么?能不能具体给我讲讲,举个例子之类的
解决方案 »
- 求好一点的JSP和servlet的教程
- applet显示图片问题,急!!
- 如果类的成员变量是一个数组,将他设为私有的后。如果让外界使用他呢?
- 求教字节流,字符流区别
- 请教个 Eclipse环境问题!谢谢!
- 做swing程序时如何在不同的容器中传递事件
- 面试题60分!请大家帮忙
- 为什么使用clone()的类要implements Cloneable?
- 请问怎样直接将swing控件放置在网页的任意位置?谢谢!
- 有关The operator % is undefined for the argument type(s) int, String 的问题
- 求助:Java中字符串替换问题?急!
- 哪位大虾能帮忙写一个自定义事件的处理过程
void draw() {}
void erase() {}
}class Circle extends Shape {
void draw() {
System.out.println("Circle.draw()");
}
void erase() {
System.out.println("Circle.erase()");
}
}class Square extends Shape {
void draw() {
System.out.println("Square.draw()");
}
void erase() {
System.out.println("Square.erase()");
}
}class Triangle extends Shape {
void draw() {
System.out.println("Triangle.draw()");
}
void erase() {
System.out.println("Triangle.erase()");
}
}public class Shapes {
public static Shape randShape() {
switch((int)(Math.random() * 3)) {
default: // To quiet the compiler
case 0: return new Circle();
case 1: return new Square();
case 2: return new Triangle();
}
}
public static void main(String[] args) {
Shape[] s = new Shape[9];
// Fill up the array with shapes:
for(int i = 0; i < s.length; i++)
s[i] = randShape();
// Make polymorphic method calls:
for(int i = 0; i < s.length; i++)
s[i].draw();
}
} ///:~此例子便是动态绑定的例子。。好好看看吧thinking in Java里的