public Car{
public enum Color{RED,BLUE};
private Color color;
Car(Car.Color c)
{
this.color =c
}
}
is it the correct way?
public Car{
public enum Color{RED,BLUE};
private Color color;
Car(Car.Color c)
{
this.color =c
}
}
is it the correct way?
Yep, that's ok. you can expose a getter to the private member as well. So other classes could see the car's color.
Its correct. Although I'd keep the enum in a separate file Color.java, because its quite generic.
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).