using enum in a class?
public Car{
public enum Color{RED,BLUE};
private Color c开发者_C百科olor;
Car(Car.Color c)
{
this.color =c
}
}
is it the correct way?
Its correct. Although I'd keep the enum in a separate file Color.java, because its quite generic.
Looks ok.
What other options do you have?
Yep, that's ok. you can expose a getter to the private member as well. So other classes could see the car's color.
Jep, looks good.
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).
精彩评论