|
Bestehende Klassen können mit Vererbung um Datenkomponenten erweitert werden Beispiel: public
class Point {
public
int x;
public
int y;
public
Point() {
this(0,0);
}
public
Point(int x, int y) {
this.x = x;
this.y = y;
}
}
Erweiterung: public
class ColoredPoint
extends Point {
public
int color;
ColoredPoint() {
super(); // redundant: default
color = 0;
}
ColoredPoint(int x, int y, int color) {
super(x,y);
this.color = color;
}
}
|
| Die Klasse ColoredPoint enthält die drei Variablen x, y und color. | |
|
Es können nur zusätzliche Datenfelder definiert werden. Eine Redefinition ist nicht möglich. |
|
| Überdeckte Felder können immer noch über super erreicht werden. |
| Letzte Änderung: 14.02.2012 | © Prof. Dr. Uwe Schmidt |