Java News-collector wrote:
> 
> Obviously you have limited knowledge/experience with the internals of
> object-oriented environments.  I wouldn't be too quick to call the object
> construction/initialization sequence "dumb" without a detailed analysis.
> 
> I would be inclined to say that calling an abstract/virtual method that
> must be defined in a subclass from within a constructor is a bad/dangerous
> programming practice that will yield unpredictable results, at best.

Or, as it says somewhere in the Bible, "Things have to happeneth in some
order." The initialization sequence wouldn't seem at all "dumb" if the
initialization of DerivedClass.d depended on data in the superclass.
Unless you propose to put the JVM into the expensive business of
discovering dependencies and cycles, you should find the Java order of
initialization to be perfectly reasonable.

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 ();
> >   }
> > }

Reply via email to