tags:

views:

87

answers:

6
public Car{

public enum Color{RED,BLUE};
private Color color;

Car(Car.Color c)
{
this.color =c

}


}

is it the correct way?

+1  A: 

Looks ok.

What other options do you have?

helios
+1  A: 

Yep, that's ok. you can expose a getter to the private member as well. So other classes could see the car's color.

Adibe7
It's quite possible that the color doesn't need to be exposed. Making the enum public so that any caller can pass an instance into the constructor still makes sense. In general, the less information that's arbitrarly exposed the more robust the class design is.
Andrzej Doyle
+1  A: 

Jep, looks good.

tob
+4  A: 

Its correct. Although I'd keep the enum in a separate file Color.java, because its quite generic.

naikus
I would also rename the enum to avoid conflicts with `java.awt.Color`
Carlos Heuberger
+1  A: 

I can't see anything wrong with this.

Ardman
A: 

You can put an enum inside a class, just like you can create another class inside a class (that would be a nested class, and if it's not static it's an inner class).

Jesper