Vidhan Chandra
Vidhan Chandra

Reputation: 19

Color[] col= {Color.RED,Color.BLUE}; what does it means in java?

I'm reading java swing and i'm having problem in understanding it. Is Color a class?

Color[] col= {Color.RED,Color.BLUE}; 

What does it means in java?

Upvotes: 0

Views: 621

Answers (3)

Zyndoras
Zyndoras

Reputation: 33

Color is a class, that has several constants, for instance RED and BLUE. These two instances of the class Color are put into an array. So you have something like a "list" with two colors.

Upvotes: 0

Color is a Class and that line of code is declaring AND initializing an array of colors with the name col and initializing it with the constants

Color.RED and Color.BLUE

Upvotes: 0

ItamarG3
ItamarG3

Reputation: 4122

Is Color a class?

Yes.

Color is a class that has many static members for the different colors, as well as a constructor for a specific color (RGB values).

What this means

Color[] col= new Color[]{Color.RED,Color.BLUE};

is an array of Colors called col which has the values of red and blue. Notice I've changed it from Color[] col= {Color.RED,Color.BLUE}; to Color[] col = new Color[]{Color.RED,Color.BLUE}; because you have to actually create the color array (hence the new keyword).

Upvotes: 1

Related Questions