OOP / language design question

cctv.star at gmail.com cctv.star at gmail.com
Tue Apr 25 07:05:00 EDT 2006


Diez B. Roggisch wrote:
> I have another question for you: why does JAVA enforce that a constructor of
> a base-class must be called prior to everything else in the derived class's
> constructor?
Well, I can imagine it's done to make sure that the base(s) are
properly constructed. Sound s sensible to me.

> No way to do some computing for parameters that I want to pass
> to the parent constructor...

Try this:

Derived::Dreived() : Base(calcParam1(), calcParam2())
...

> Besides, this automatically base-constructor-calling only happens for the
> most trivial of cases - the no-argument-constructors.

Well, the language can at least ensure that theconstructor is called -
i.e. either call it automatically if it can be called without
parameters, or fail with error.




More information about the Python-list mailing list