Java Reference
In-Depth Information
ColoredPoint() { super(); }
which invokes the constructor, with no arguments, for the direct superclass of the class
ColoredPoint
. The error is that the constructor for
Point
that takes no arguments is
private
,
and therefore is not accessible outside the class
Point
, even through a superclass con-
Two more errors occur because the method
reset
of class
Point
is
private
, and therefore
is not inherited by class
ColoredPoint
. The method invocations in method
clear
of class
ColoredPoint
and in method
main
of class
Test
are therefore not correct.
Example 8.2-2. Inheritance of Class Members with Default Access
Consider the example where the points package declares two compilation units:
package points;
public class Point {
int x, y;
public void move(int dx, int dy) { x += dx; y += dy; }
}
and:
package points;
public class Point3d extends Point {
int z;
public void move(int dx, int dy, int dz) {
x += dx; y += dy; z += dz;
}
}
and a third compilation unit, in another package, is:
import points.Point3d;
class Point4d extends Point3d {
int w;
public void move(int dx, int dy, int dz, int dw) {
x += dx; y += dy; z += dz; w += dw; // compile-time errors
}
}