currentColor = getCarColor(this.car.color)
这里的color
是私有的,而getCarColor
是一个方法,我如何访问变量color
?
You should not be accessing private variables directly: they are made private for a reason.
The proper way to do it is to add a public accessor method for the color to the car:
class Car {
private Color color;
// Add this method:
public Color getColor() { return color; }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.