OnJava8-Examples/enums/OverrideConstantSpecific.java
2015-11-03 12:00:44 -08:00

22 lines
477 B
Java

// enums/OverrideConstantSpecific.java
public enum OverrideConstantSpecific {
NUT, BOLT,
WASHER {
@Override
void f() { System.out.println("Overridden method"); }
};
void f() { System.out.println("default behavior"); }
public static void main(String[] args) {
for(OverrideConstantSpecific ocs : values()) {
System.out.print(ocs + ": ");
ocs.f();
}
}
}
/* Output:
NUT: default behavior
BOLT: default behavior
WASHER: Overridden method
*/