|
|
Re: super man! Always be the first statements.
|
Posted: Jun 24, 2007 2:47 PM
|
|
As you may be aware, when a class has no constructor then an "implicit" constructor is inserted into the class when it is compiled (which takes no arguments and is empty (well almost empty - see below).
Similarly when the first line of a constructor does not explicitly contain a call to another constructor, either of the parent class or within the same class, then an implicit "no arguments" call to the constructor of the parent class is also inserted.
The purpose of all this is to ensure that all the internal components of an object are constructed in the correct order (from the most general high level object in the object's hierarcy to the most specific). This is necessary because it is possible for a class to reference components in the parent hierarchy during its construction, therefore those components need to be created first.
If the call to a super constructor (explicit or implicit, directly or via another constructor in the same class) was not the first thing that happened in the constructor then it would not be possible to guarantee the existance of the parent object for use by whatever else might otherwise be the first line of the construtor.
|
|