Frage

currentColor = getCarColor(this.car.color)

Here color is private and getCarColor is a method, how do I access the variable color?

War es hilfreich?

Lösung

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; }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top