【问题标题】:Initializing Enum variable in abstract class在抽象类中初始化枚举变量
【发布时间】:2014-03-08 02:46:27
【问题描述】:

我应该将 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};

【问题讨论】:

    标签: java class service enums abstract-class


    【解决方案1】:

    试试看:

    et = Jobs.NONE;
    

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

    【讨论】:

    • 天啊!哇,为什么我以前没有想过尝试这个。主要面掌。非常感谢! :D 成功了
    猜你喜欢
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多