Aqualon
2004-11-28, 22:37:43
Ich habe ein ziemlich seltsames Problem mit Default Konstruktoren in Java.
Folgende Klassen spielen eine Rolle:
abstract class ALGOBinaryExpression extends ALGOExpression {
protected ALGOExpression rightArg;
protected ALGOExpression leftArg;
/**
* default constructor
*/
public ALGOBinaryExpression() {
System.err.println("Syntax Error! I need 2 Arguments!");
}
}
class ALGONestedExpression extends ALGOBinaryExpression {
private ALGOExpression firstArg;
/**
* Default Constructor
*/
public ALGONestedExpression() {
}
/**
* Constructor uses param to set firstArg
*/
public ALGONestedExpression(ALGOExpression x) {
firstArg = x;
}
}
Wenn ich nun ein neues Objekt von ALGONestedExpression erstelle (mit einer ALGOExpression als Argument), wird neben dem Konstruktor ALGONestedExpression(ALGOExpression x) auch der default Konstruktor von ALGOBinaryExpression aufgerufen.
Meine Frage, wieso wird dies gemacht?
Aqua
Folgende Klassen spielen eine Rolle:
abstract class ALGOBinaryExpression extends ALGOExpression {
protected ALGOExpression rightArg;
protected ALGOExpression leftArg;
/**
* default constructor
*/
public ALGOBinaryExpression() {
System.err.println("Syntax Error! I need 2 Arguments!");
}
}
class ALGONestedExpression extends ALGOBinaryExpression {
private ALGOExpression firstArg;
/**
* Default Constructor
*/
public ALGONestedExpression() {
}
/**
* Constructor uses param to set firstArg
*/
public ALGONestedExpression(ALGOExpression x) {
firstArg = x;
}
}
Wenn ich nun ein neues Objekt von ALGONestedExpression erstelle (mit einer ALGOExpression als Argument), wird neben dem Konstruktor ALGONestedExpression(ALGOExpression x) auch der default Konstruktor von ALGOBinaryExpression aufgerufen.
Meine Frage, wieso wird dies gemacht?
Aqua