开发者

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜