This may sound like a stupid question but aside from the obvoius technical

reason(s), can someone please give a real-world example where this could
be used ( ie.. calling a instanance method(s) in the constructor of the
superclass before
the superclass has been completely constructed)?

Nathan Meyers wrote:

> Richard Jones wrote:
> >
> > Can someone tell me why this program, when run under
> > Linux, prints d = 0 (ie. the variable d isn't being
> > initialized as expected)? According to Bruce Eckel's
> > book, which is the only reference I have available to
> > me, d should be initialized to 1, so I suspect this
> > may be a JVM bug ...
>
> Have you tried it on JVMs other than Linux?
>
> It looks to me like you're invoking method() before DerivedClass has
> been fully initialized... not entirely surprising, since the super()
> constructor must occur before any constructor activity in the derived
> class. (Try, for example, inserting some code before the super() call
> and you'll be scolded by the compiler. The initialization of d is
> comparable activity.)
>
> Nathan Meyers
> [EMAIL PROTECTED]
>
>
> > ---------------------------------------------------------
> > /* SuperClass.java */
> >
> > public abstract class SuperClass
> > {
> >   protected SuperClass ()
> >   {
> >     method ();
> >   }
> >
> >   protected abstract void method ();
> > }
> > ---------------------------------------------------------
> >
> > ---------------------------------------------------------
> > /* DerivedClass.java */
> >
> > public class DerivedClass extends SuperClass
> > {
> >   public int d = 1;
> >
> >   public DerivedClass ()
> >   {
> >     super ();
> >   }
> >
> >   protected void method ()
> >   {
> >     System.out.println ("d = " + d);
> >   }
> >
> >   public static void main (String[] args)
> >   {
> >     DerivedClass derivedClass = new DerivedClass ();
> >   }
> > }
> > ---------------------------------------------------------
> >
> > $ java -version
> > java version "1.1.6"
> > $ java DerivedClass
> > d = 0
> >
> > --
> > -      Richard Jones. Linux contractor London and SE areas.        -
> > -    Very boring homepage at: http://www.annexia.demon.co.uk/      -
> > - You are currently the 1,991,243,100th visitor to this signature. -
> > -    Original message content Copyright (C) 1998 Richard Jones.    -

Reply via email to