Java Reference
In-Depth Information
Finally, the actual statements of the constructor body are executed. If
that constructor was invoked explicitly, then upon completion, control
returns to the constructor that invoked it, and executes the rest of its
body. This process repeats until the body of the constructor used in the
new construct has been executed.
If an exception is thrown during the construction process, the new ex-
pression terminates by throwing that exceptionno reference to the new
object is returned. Because an explicit constructor invocation must be
the first statement in a constructor body, it is impossible to catch an
exception thrown by another constructor. (If you were allowed to catch
such exceptions it would be possible to construct objects with invalid ini-
tial states.)
Here is an example you can trace to illustrate the different stages of
construction:
class X {
protected int xMask = 0x00ff;
protected int fullMask;
public X() {
fullMask = xMask;
}
public int mask(int orig) {
return (orig & fullMask);
}
}
class Y extends X {
protected int yMask = 0xff00;
public Y() {
fullMask |= yMask;
 
Search WWH ::




Custom Search