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 }".
  1. "CardType" is the name of the enum and "CROSS, HEART, ..." are different values that a CardType variable can take.
  2. If you want to use a CardType variable, just write "CardType type = CardType.CROSS".
  3. 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}".
Java offers many more function and classes that you can use to extend your program and its functionality. For example, you have the possibility to convert a string into an integer. To do this, all you need is a function. Um mit Java zu programmieren, sollten Sie außerdem wissen, was genau eine Klasse ist und wie Sie diese richtig verwenden, damit das Programm das tut, was es soll.

By Nixie

PayPal: Delayed availability - this option is available :: Find child support number on bank statement
USEFUL LINKS