[4598] in java-interest
Re: calling non-default constructor for derived classes?
daemon@ATHENA.MIT.EDU (Pat Niemeyer)
Mon Jan 8 18:45:39 1996
Date: Mon, 8 Jan 1996 16:14:04 -0600 (CST)
From: Pat Niemeyer <pat@icon-stl.net>
To: brian sharon <brian@jjt.com>
cc: java-interest@java.sun.com
In-Reply-To: <Pine.LNX.3.91.960108121620.9756A-100000@longhorn.jjt.com>
On Mon, 8 Jan 1996, brian sharon wrote:
> 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
> }
> }
>
...
> This does not work in Java (at least when I try it). Nor does:
>
> NewClass(int whatever) {
> this.BaseClass(whatever);
> }
Close.
You want
NewClass(int whatever) {
super(whatever);
...
}
(as opposed to this(whatever), but not this.??(whatever))
It should be the very first line of your constructor.
Pat
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com