I completed the following code per the instructions for a homework assignment:
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();
}
Initially, however, I tried to do: public abstract String acctType(); and received the following error on each of the overridden methods:
stringValue() in cannot override stringValue() in AccountType;
attempting to assign weaker access privileges;
was public
So my question is what is going on with the public modifier on the abstract method? The enum itself is declared as a public class, so I don’t understand the bit about assigning weaker access privileges when both should seem to be public.
The error message means that if you define the abstract method with a specific visibility, you have to define the implementations to have at least that visibility.
In this specific situation that means if the abstract method is public, the implementations have to be as well.