OnJava8-Examples/enums/OverrideConstantSpecific.java
2015-12-15 11:47:04 -08:00

25 lines
657 B
Java

// enums/OverrideConstantSpecific.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
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
*/