我有一个 Employee 类和部门类。现在在员工中我有一个部门作为其成员。该部门可以是 2 种类型“HR”或“Admin”。现在我应该在单独的文件中将 Departmentype 声明为枚举吗接口(interface),然后应该建模部门类,如下所示?
public interface Myconstants{
enum Depttype{HR,Admin};
}
public class Department{
Myconstants.Depttype depttype;
Department(Myconstants.Depttype depttype){
this.deptype = deptype;
}
最佳答案
我只需在 Department 类上声明枚举即可。
public class Department {
public enum Depttype{HR,Admin};
private Depttype depttype;
Department(Depttype depttype) {
this.deptype = deptype;
}
}
关于java - java中设计类的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3475318/