Java Reference
In-Depth Information
public enum ETemp {
C1 {
// Body of constant C1
public int getValue() {
return 100;
}
},
C2 {
// Body of constant C2
public int getValue() {
return 0;
}
},
C3 {
// Body of constant C3
public int getValue() {
return 0;
}
};
// Provide default implementation for getValue() method
public abstract int getValue();
}
Let's enhance your SmartSeverity enum type. You are running out of good names for your enum type. You will
name the new one SuperSmartSeverity . Listing 18-5 has the code.
Listing 18-5. Using a Body for Enum Constants
// SuperSmartSeverity.java
package com.jdojo.enums;
public enum SuperSmartSeverity {
LOW("Low Priority", 30) {
public double getProjectedCost() {
return 1000.0;
}
},
MEDIUM("Medium Priority", 15) {
public double getProjectedCost() {
return 2000.0;
}
},
HIGH("High Priority", 7) {
public double getProjectedCost() {
return 3000.0;
}
},
URGENT("Urgent Priority", 1) {
public double getProjectedCost() {
return 5000.0;
}
};
 
Search WWH ::




Custom Search