【发布时间】:2012-08-08 14:17:45
【问题描述】:
可能重复:
In Java, what's the difference between public, default, protected, and private?
为什么一个包中的子类不能通过超类的引用访问它的超类(在另一个包中)的受保护成员?我正在为此苦苦挣扎 观点。请帮帮我
package points;
public class Point {
protected int x, y;
}
package threePoint;
import points.Point;
public class Point3d extends Point {
protected int z;
public void delta(Point p) {
p.x += this.x; // compile-time error: cannot access p.x
p.y += this.y; // compile-time error: cannot access p.y
}
【问题讨论】:
标签: java subclass access-specifier