Java Reference
In-Depth Information
its own constructor. It is common to have an extended class that has no
constructor signatures in common with its superclass.
Constructors are not methods and are not inherited. If the superclass
defines a number of constructors and an extended class wishes to have
constructors of the same form, then the extended class must explicitly
declare each constructor, even if all that constructor does is invoke the
superclass constructor of the same form.
3.2.1. Constructor Order Dependencies
When an object is created, memory is allocated for all its fields, includ-
ing those inherited from superclasses, and those fields are set to default
initial values for their respective types (zero for all numeric types, false
for boolean , '\u0000' for char , and null for object references). After this,
construction has three phases:
1. Invoke a superclass's constructor.
2. Initialize the fields using their initializers and any initialization
blocks.
3. Execute the body of the constructor.
First the implicit or explicit superclass constructor invocation is ex-
ecuted. If an explicit this constructor invocation is used then the chain
of such invocations is followed until an implicit or explicit superclass con-
structor invocation is found. That superclass constructor is then invoked.
The superclass constructor is executed in the same three phases; this
process is applied recursively, terminating when the constructor for Ob-
ject is reached because there is no superclass constructor at that point.
Any expressions evaluated as part of an explicit constructor invocation
are not permitted to refer to any of the members of the current object.
In the second stage all the field initializers and initialization blocks are
executed in the order in which they are declared. At this stage referen-
ces to other members of the current object are permitted, provided they
have already been declared.
 
Search WWH ::




Custom Search