next up previous contents index
Next: Vererbung: Wann und wie? Up: Programmieren in Java Previous: Sichtbarkeitsspezifikationen

Vererbung

Neben der Komposition (Seite gif) 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

tex2html_wrap2162

public Object();

tex2html_wrap2164

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




next up previous contents index
Next: Vererbung: Wann und wie? Up: Programmieren in Java Previous: Sichtbarkeitsspezifikationen

Peter Pfahler, 1997