HOME
> System software
> Java: Enum - So Important Are Enumerations
Java: Enum - so important are enumerations
Java is a programming language that is widely used and is considered one of the first object-oriented languages. An enum, which is an enumeration, is used to specify constant variables. Usually, it is used to define certain properties of an object, for example the day of the week.
How does an enum work in Java?
It is relatively easy to create an enum in Java, you just need to specify the enum name and the associated variables: "public enum CardType { CROSS, HEART, PEAK, KARO }".- "CardType" is the name of the enum and "CROSS, HEART, ..." are different values that a CardType variable can take.
- If you want to use a CardType variable, just write "CardType type = CardType.CROSS".
- You can now use the CardType variable normally, like other variables. For example, you can make a new assignment "type = CardType.HEART" or you can compare two variables "if (type == CartType.CROSS) { //dosomething}".