[4601] in java-interest

home help back first fref pref prev next nref lref last post

Re: calling non-default constructor for derived classes?

daemon@ATHENA.MIT.EDU (Amy Fowler)
Mon Jan 8 23:39:21 1996

Date: Mon, 8 Jan 1996 16:43:59 -0800
From: Amy.Fowler@Eng.Sun.COM (Amy Fowler)
To: java-interest@java.Eng.Sun.COM, brian@jjt.com


>>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)?

Try:

    NewClass(int whatever) {
    	super(whatever);
    	// more stuff here
    }
    
(note that if you call the superclass's constructor from the
subclass's, it must be the first thing you do in the constructor)

Good Luck,
Amy Moore-Fowler
Java Products Group
Sun Microsystems, Inc.
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post