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-
structor invocation (ยง 8.8.7 ) .
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:
Click here to view code image
package points;
public class Point {
int x, y;
public void move(int dx, int dy) { x += dx; y += dy; }
}
and:
Click here to view code image
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:
Click here to view code image
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
}
}
Search WWH ::




Custom Search