Article View: borland.public.jbuilder.java.language
Article #15018Re: Illogical constructor behaviour?
From: Tor Iver Wilhelmsen
Date: Mon, 12 Jul 1999 00:00
Date: Mon, 12 Jul 1999 00:00
15 lines
1180 bytes
1180 bytes
Tom.Eugelink@OVSoftware.com writes: > It seems to me there is no reason why the declares shouldn't be > executed when the constructor is entered instead of just before the > first line in the constructor... Your _actual_ problem is that fireman.display() _masks_ person.display(), and methods are invoked dynamically. It's a flaw in the program design, not the language: You should not invoke methods that are not private or final in a constructor of a non-final class, because a subclass can override it - like in your example. Basically, superclass constructor invocation goes before any initialization of fields in the subclass, which leads to the NullPointerException in your example.
Technical Details
Message-ID:
<uzp1241hv.fsf@sds.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3789a7ea.1163072@forums.inprise.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,c150801d0979e255 X-Google-Attributes: gidf74b3,public From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no> Subject: Re: Illogical constructor behaviour? Date: 1999/07/12 Message-ID: <uzp1241hv.fsf@sds.no> X-Deja-AN: 500054701 Sender: towi@SDSA1761 References: <3789a7ea.1163072@forums.inprise.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language