[3385] in java-interest
super() must be first
daemon@ATHENA.MIT.EDU (Gary Aitken)
Thu Nov 9 23:29:41 1995
Date: Thu, 9 Nov 1995 18:29:41 -0700
From: garya@village.org (Gary Aitken)
To: java-interest@java.sun.com
The current implementation requires that any call to super(...) be the
first statement in the body of a constructor.
Consider the case where a base class constructor takes an array as
an argument, and a derived class takes discrete variables which are
used to build the array used by the base class. Is there a way to
do this? Or must one resort to using a default base class constructor
and a function to set the array?
e.g.
class base {
int n_pts;
int pts[];
// base( int n, int pt[] ) { n_pts=n; pts=pt; } // want to use this
base() { n_pts=0; pts=null; } // have to do this
void setPoints( int n, int pt[] ) { n_pts=n; pts=pt; } // and this
}
class derived extends base {
derived( int x1, int x2 ) {
int xpts[] = new int[2];
x[0] = x1;
x[1] = x2;
// super( 2, xpts ); // This is what we want to do
setPoints( 2, xpts ); // This is what we have to do
};
}
Gary Aitken garya@village.org
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com