为什么我可以在没有getter(colour == ((ColouredPoint) other).colour
)的情况下访问具有私有访问权限的变量?以下是我的ColouredPoint
类的代码:
public class ColouredPoint extends Point {
private Colour colour;
public ColouredPoint(double x, double y, double z, Colour colour) {
super(x, y, z);
this.colour = colour;
}
@Override
public String toString() {
return "(" + super.toString() + ", " + colour + ")";
}
@Override
public boolean equals(Object other) {
if (other instanceof ColouredPoint) {
return x == ((ColouredPoint) other).x
&& y == ((ColouredPoint) other).y
&& z == ((ColouredPoint) other).z
&& colour == ((ColouredPoint) other).colour;
}
return false;
}
}