Java Reference
In-Depth Information
•
Superclass constructor invocations
begin with either the keyword
super
(possibly
prefaced with explicit type arguments) or a
Primary
expression. They are used to
invoke a constructor of the direct superclass.
Superclass constructor invocations may be subdivided:
♦
Unqualified superclass constructor invocations
begin with the keyword
super
(possibly prefaced with explicit type arguments).
♦
Qualified superclass constructor invocations
begin with a
Primary
expression.
They allow a subclass constructor to explicitly specify the newly created ob-
ject's immediately enclosing instance with respect to the direct superclass
An explicit constructor invocation statement in a constructor body may not refer to any
instance variables or instance methods or inner classes declared in this class or any super-
class, or use
this
or
super
in any expression; otherwise, a compile-time error occurs.
The exception types that an explicit constructor invocation statement can throw are speci-
Example 8.8.7.1-1. Qualified Superclass Constructor Invocation
class Outer {
class Inner {}
}
class ChildOfInner extends Outer.Inner {
ChildOfInner() { (new Outer()).super(); }
}
Example 8.8.7.1-2. Restrictions on Explicit Constructor Invocation Statements
lows:
class Point {
int x, y;
Point(int x, int y) { this.x = x; this.y = y; }
}
class ColoredPoint extends Point {
static final int WHITE = 0, BLACK = 1;
int color;