OnJava8-Examples/enums/OverrideConstantSpecific.java
Bruce Eckel 186333e022 enums
2015-05-31 10:58:40 -07:00

23 lines
529 B
Java

//: enums/OverrideConstantSpecific.java
// ©2015 MindView LLC: see Copyright.txt
import static net.mindview.util.Print.*;
public enum OverrideConstantSpecific {
NUT, BOLT,
WASHER {
@Override
void f() { print("Overridden method"); }
};
void f() { print("default behavior"); }
public static void main(String[] args) {
for(OverrideConstantSpecific ocs : values()) {
printnb(ocs + ": ");
ocs.f();
}
}
} /* Output:
NUT: default behavior
BOLT: default behavior
WASHER: Overridden method
*///:~