June 2025
Intermediate to advanced
1129 pages
53h
English
Each enumeration type inherits from the special class Enum . For this next example, let’s define some countries:
public enum Country { GERMANY, UK, CHINA}
Listing 8.19 src/main/java/com/tutego/insel/enums/v1/Country.java (Snippet)
The compiler translates this code into an enumeration class that resembles the following code:
public class Country extends Enum { public static final Country GERMANY = new Country( "GERMANY", 0 ); public static final Country UK = new Country( "UK", 1 ); // other constants... private Country( String s, int i ) { super( s, i ); } // other methods...}
Each enumeration element is an object that automatically has some default methods coming from the superclass ...
Read now
Unlock full access