Enum In java
In java we use of enum is not confined to declaring set of constants , introduced in J2SE 5.0, is useful when you want a variable to hold only a predetermined set of values. Just like a class, an enum can have constructors, methods, and variables in addition to the constants.
The most interesting fact about enum is enum can be used as a stand alone application as we can define the main method in it , the following code describe the use of enum in java with main method.
enum Cars {
THAR,XUV,SCORPIO;
static public void main(String[] args) {
for (Cars name : Cars.values())
System.out.print(name + " ");
}
}
In the following code the enum Cars is created with three constants THAR, XUV, SCORPIO , it have a main method to print the all constants of the enum.
0 Comment(s)