From JLS 6.6.2 :
A protected member or constructor of an object can be accessed from outside the package in which it is declared only by the code responsible for the implementation of this object.
From 6.6.2.1 :
Let C be the class in which the protected member is declared. Access is permitted only inside the body of subclass S of C.
this.first = 5;It works because it Bis a developer A.
A.second , . B.second.
, , , , - . 6.6.2.1 , , :
, :
package points;
public class Point {
protected int x, y;
void warp(threePoint.Point3d a) {
if (a.z > 0)
a.delta(this);
}
}
threePoint :
package threePoint;
import points.Point;
public class Point3d extends Point {
protected int z;
public void delta(Point p) {
p.x += this.x;
p.y += this.y;
}
public void delta3d(Point3d q) {
q.x += this.x;
q.y += this.y;
q.z += this.z;
}
}
delta : x y p, , Point3d (, x y), Point (, x y), ( p). delta3d q, Point3d Point Point3d.
protected static Java.
protected - protected static protected, .