Neben der Komposition (Seite ) die wichtigste Form
der Wiederverwendung auf der Basis von Klassen.
Eine Oberklasse
class point { private float x,y; static int pcount = 0; public point(float x,float y) { this.x = x; this.y = y; pcount++; } public point() { this(0.0, 0.0); } public void move(float dx, float dy) { x += dx; y += dy; } }
wird zu Implementierung einer neuen Klasse wiederverwendet:
class point3D extends point { private float z; public point3D(float x, float y, float z) { super(x, y); this.z = z; } public point3D() { this(0.0, 0.0, 0.0); } public void move(float dx, float dy, float dz) { move(dx, dy); z += dz; } }
Jede Java-Klasse benutzt Vererbung:
Durch direkte oder indirekte Vererbung ist Object die Oberklasse aller Java-Klassen.
Wie sieht Object aus?
Information aus der Dokumentation der JDK APIs.
Oder direkt von java.sun.com
public Object();
public final native Class getClass() public native int hashCode() public boolean equals(Object obj) public native Object clone() public String toString() protected void finalize()
außerdem 5 Methoden zur thread-Behandlung:
notify, notifyAll, wait