public class EnumInsideDemo
{
/*
* Enum is Defined inside of the class.
*/
private enum Day
{
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
public static void main(String[] args)
{
/*
* The java compiler internally adds the values()
* method when it creates an enum. The values()
* method returns an array containing all the values
* of the enum.
*/
Day[] daysArray = Day.values();
for (Day day : daysArray)
{
System.out.println(day);
}
}
}
Output SUNDAY
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
EnumOutsideDemo.java /*
* Enum is Defined outside of the class.
*/
enum Day
{
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
public class EnumOutsideDemo
{
public static void main(String[] args)
{
/*
* The java compiler internally adds the values()
* method when it creates an enum. The values()
* method returns an array containing all the values
* of the enum.
*/
Day[] daysArray = Day.values();
for (Day day : daysArray)
{
System.out.println(day);
}
}
}
Output SUNDAY
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
Click the below link to download the code:https://sites.google.com/site/ramj2eev1/home/javabasics/EnumDemo_define_App.zip?attredirects=0&d=1Github Link:https://github.com/ramram43210/Java/tree/master/BasicJava/EnumDemo_define_AppBitbucket Link:https://bitbucket.org/ramram43210/java/src/4ee0c57df034098ab5ebc06d5a6296fa5950097a/BasicJava/EnumDemo_define_App/?at=masterSee also: All JavaEE Viedos PlaylistAll JavaEE ViedosAll JAVA EE LinksServlets TutorialAll Design Patterns LinksJDBC TutorialJava Collection Framework TutorialJAVA TutorialKids Tutorial