Java Reference
In-Depth Information
ColoredPoint(int x, int y) {
this(x, y, color); // Changed to color from WHITE
}
ColoredPoint(int x, int y, int color) {
super(x, y);
this.color = color;
}
}
then a compile-time error would occur, because the instance variable
color
cannot be
used by a explicit constructor invocation statement.
Let
C
be the class being instantiated, and let
S
be the direct superclass of
C
.
If a superclass constructor invocation statement is qualified, then:
• If
S
is not an inner class, or if the declaration of
S
occurs in a static context, then a
compile-time error occurs.
• Otherwise, let
p
be the
Primary
expression immediately preceding “
.super
”. Let
O
be the innermost lexically enclosing class of
S
.
It is a compile-time error if the type of
p
is not
O
or a subclass of
O
, or if the type
If a superclass constructor invocation statement is unqualified, and if
S
is an inner member
class, then it is a compile-time error if
S
is not a member of a lexically enclosing class of
C
by declaration or inheritance.
Evaluation of an alternate constructor invocation statement proceeds by first evaluating the
arguments to the constructor, left-to-right, as in an ordinary method invocation; and then
invoking the constructor.
Evaluation of a superclass constructor invocation statement is more complicated, as fol-
lows:
1.
Let
C
be the class being instantiated, let
S
be the direct superclass of
C
, and let
i
be
the instance being created.
2.
The immediately enclosing instance of
i
with respect to
S
(if any) must be determ-
ined:
• If
S
is not an inner class, or if the declaration of
S
occurs in a static context, no
immediately enclosing instance of
i
with respect to
S
exists.