[4591] in java-interest
calling non-default constructor for derived classes?
daemon@ATHENA.MIT.EDU (brian sharon)
Mon Jan 8 14:56:51 1996
Date: Mon, 8 Jan 1996 12:29:12 -0600 (CST)
From: brian sharon <brian@jjt.com>
To: java-interest@java.sun.com
Another basic question, I'm sure. Here is a simple example:
class BaseClass {
BaseClass(int whatever) {
// some stuff here
}
}
class NewClass extends BaseClass {
NewClass(int whatever) {
// more stuff here
}
}
How do I ensure that BaseClass(int) gets called when I initialize a
NewClass object as NewClass(int)?
In C++, I know that I would do the following:
NewClass(int whatever) : BaseClass(whatever) {
// NewClass specific initialization here
}
This does not work in Java (at least when I try it). Nor does:
NewClass(int whatever) {
this.BaseClass(whatever);
}
which doesn't surprise me - I didn't really expect that one to work.
So - is there a syntax for getting at the non-default constructors of a
superclass? Or does the fact that I'm asking this question reveal a fault
in my Java-thinking?
I'm sure there's a "yes" answer to at least one of those questions, and
probably to both.
Thanks everybody,
--brian brian@jjt.com
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com