🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16532

Re: Java Bug or tough certification exam question for you concerning static initializers

#16532
From: Tor Iver Wilhelmsen
Date: Wed, 10 Feb 1999 00:00
33 lines
1839 bytes
"Wido Riezebos" <[REMOVE_THIS]w.riezebos@itude.com> writes:

> Now here's the question: WHY DOES'NT THE SECOND STATIC INITIALIZER FIRE?? Is
> it because the jvm decides it does not need to load the B class since it
> thinks the str is defined in A and B is an A?

Replace "thinks" with "knows": That you can refer to static members of
parent classes via the derived class, or any static members via
instance refs is a great source of confusion and the gnashing of
teeth. :-)

Try running "javap -c" on the resulting class, and you will see that
it uses A's "str", since static members are not inherited. Period.

> The certification question: (multiple multiple choice)
> 1) This is a Bug
> 2) This is a Feature
> 3) This is Not Defined
> 4) Some of the above
> 5) I need some asperine

The answer is <drumroll/> 2. The compiler is just being lenient in how
your reference to "A.str" is declared in the program.

(Hm. Hint to Sun: Add a "-strict" option to javac in order to turn off
such fetures as:

  1. Referring to static members via any other mechanism than the
     explicit class/interface in question.
  2. String concatenation with "+" - the programmer will need to
     explicify the use of StringBuffer.
  3. Possibly other syntactic sugar, like anonymous inner classes.
)
Technical Details
Message-ID: <u3e4eijhw.fsf@sds.no>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <79rmjc$99p15@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,1512ce46783b168a
X-Google-Attributes: gidf74b3,public
From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no>
Subject: Re: Java Bug or tough certification exam question for you concerning static initializers
Date: 1999/02/10
Message-ID: <u3e4eijhw.fsf@sds.no>
X-Deja-AN: 442767750
Sender: towi@SDSA1761
References: <79rmjc$99p15@forums.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language