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