electroiv
electroiv

Reputation: 168

Is java.awt.color.RED an object or an attribute?

Color.GREEN looks like an attribute and not an object if so then how can I assign class member(Color.GREEN) to an object reference of type Color?

import java.awt.*;

public class StopLight {

    public static final Color GREEN = Color.GREEN;
    public static final Color YELLOW = Color.YELLOW;
    public static final Color RED = Color.RED;


    public StopLight() {
        state = GREEN;
    }

    private Color state;
}

Upvotes: 0

Views: 483

Answers (2)

Kayaman
Kayaman

Reputation: 73568

It's a constant, and of course an object of class Color.

Upvotes: 1

SomeDude
SomeDude

Reputation: 14238

It is a public static object defined in java awt's Color :

/**
 * The color green.  In the default sRGB space.
 */
public final static Color green     = new Color(0, 255, 0);

/**
 * The color green.  In the default sRGB space.
 * @since 1.4
 */
public final static Color GREEN = green;

So you can access it as Color.GREEN.

Upvotes: 2

Related Questions