【发布时间】:2012-07-18 01:42:11
【问题描述】:
我按照家庭作业的说明完成了以下代码:
public enum AccountType {
Checking {
@Override
String acctType() { return "Checking Account"; }
},
Savings {
@Override
String acctType() { return "Saving Account"; }
},
CreditCard {
@Override
String acctType() { return "Credit Card Account"; }
};
abstract String acctType();
}
然而,最初,我尝试这样做:public abstract String acctType(); 并在每个被覆盖的方法上收到以下错误:
stringValue() in cannot override stringValue() in AccountType;
attempting to assign weaker access privileges;
was public
所以我的问题是抽象方法上的 public 修饰符是怎么回事?枚举本身被声明为公共类,所以当两个 应该 似乎都是 public 时,我不明白分配较弱的访问权限。
【问题讨论】: