Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
student:java:enum [2023/02/20 15:31] – [Enum Types] stewarmc | student:java:enum [2023/02/24 14:13] (current) – [Enum Types] stewarmc | ||
---|---|---|---|
Line 71: | Line 71: | ||
</ | </ | ||
- | Java programming language enum types are much more powerful than their counterparts in other languages. The '' | + | Java programming language enum types are much more powerful than their counterparts in other languages. The '' |
<code java> | <code java> | ||
Planet[] planetValues = Planet.values(); | Planet[] planetValues = Planet.values(); | ||
- | for (int i = 0; i & | + | for (int i = 0; i < planetValues.length; |
Planet p = planetValues[i]; | Planet p = planetValues[i]; | ||
System.out.printf(" | System.out.printf(" | ||
Line 90: | Line 90: | ||
**Note:** The constructor for an enum type must be package-private or private access. It automatically creates the constants that are defined at the beginning of the enum body. You cannot invoke an enum constructor yourself. | **Note:** The constructor for an enum type must be package-private or private access. It automatically creates the constants that are defined at the beginning of the enum body. You cannot invoke an enum constructor yourself. | ||
- | In addition to its properties and constructor, | + | In addition to its properties and constructor, |
<code java> | <code java> | ||
public enum Planet { | public enum Planet { | ||
Line 128: | Line 128: | ||
double mass = earthWeight/ | double mass = earthWeight/ | ||
Planet[] planetValues = Planet.values(); | Planet[] planetValues = Planet.values(); | ||
- | for (int i = 0; i & | + | for (int i = 0; i < planetValues.length; |
Planet p = planetValues[i]; | Planet p = planetValues[i]; | ||
System.out.printf(" | System.out.printf(" |