We will discuss in this tutorial about the enum keyword in Java programming language
In Java programming language enum is a keyword(Special type variable) that is used to declare a new enumeration type. This keyword is rarely used in Java. It is used to declare a collection of values.
An enum is a data type which contains fixed set of constants.
class enum_ex{ enum Name_OF_Setofvalues{value_1,value_2,value_3,...........value_n} }
Example
class { Days_Of_Weeks{Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday}
program 1
class Enum_ex{ enum months { January,February,March,April,May,June,July, August,September,October,November,December } public static void main (String args[]){ for(months m:months.values()) { term_End(m); } } public static void term_End(months m){ if(m.equals(months.December)){ System.out.println(m+" :End of year"); } else { System.out.println(m+" :months of year"); } } }
When the above code is compiled and executed, it will produce the following results
January :months of year February :months of year March :months of year April :months of year May :months of year June :months of year July :months of year August :months of year September :months of year October :months of year November :months of year December :End of year
There are other Java language keywords that are similar to this keyword
class keyword in Java language
There are other Java language keywords that are similar to this keyword
Usage of this statement in the Java language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…