在抽象类中初始化Enum变量

时间:2014-03-08 02:46:27

标签: java class service enums abstract-class

我应该将et初始化为NONE,但我一直收到错误。 不断弹出的错误说“无法找到符号”。我真的不知道我做错了什么。有帮助吗?

public abstract class Worker
{
public String name;
public int socialSecurity;
private int yearsExperience;
public Jobs et = null;
public static int id;
public int currentID;

public Worker ()
{
    name = "AnyName";
    socialSecurity = 12345;
    yearsExperience = 0;
    et = NONE;
    id++;
    currentID = id;
}

public Worker (String n, int ss, int ye, Jobs j)
{
    id++;
    currentID = id;
    name = n;
    socialSecurity = ss;
    yearsExperience = ye;
    et = j;
}

public String getName()
{
    return name;
}

public int getSocialSecurity()
{
    return socialSecurity;
}

public int yearsExperience()
{
    return yearsExperience;
}

public Jobs getJobs()
{
    return et;
}

public void setName(String n1)
{
    name = n1;
}

public void setSocialSecurity(int ss1)
{
    socialSecurity = ss1;
}

public void setYearsExperience(int ye1)
{
    yearsExperience = ye1;
}

public void setJobs(Jobs et1)
{
    et = et1;
}

public abstract double benefitsCalculation(Jobs et2);
}

以下是我的枚举类

public enum Jobs {ELECTRICAL_ENGINEER, MECHANICAL_ENGINEER, ADMINISTRATIVE_SECRETARY, ADMINISTRATIVE_ASSISTAN, ENGINEERING_MANAGER, ADMINISTRATIVE_MANAGER, NONE};

1 个答案:

答案 0 :(得分:2)

试试:

et = Jobs.NONE;

并确保导入Jobs,如果它不在同一个包中。