我有一个类Game
与属性"状态",这个属性将只是"球员"或"教练",我怎么能做到这一点?我将告诉你我是如何尝试的
class Status{
public static final String player = "player";
public static final String coach = "coach";
}
class Game {
String status;
Game(String status){
this.status = status;
}
}
class Main{
public static void main(String args[]){
new Game(Status.player);
new Game(Status.coach);
}
}
谢谢
使用枚举
public class Game {
public enum Status { PLAYER, COACH };
private Status status;
public Game(Status status){
this.Status = status;
}
public static void main(String args[]){
new Game(Status.PLAYER);
new Game(Status.COACH);
}
}