Click here to watch in Youtube :
https://www.youtube.com/watch?v=F4V9gr8wd0Q&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial: Enum in java[Define Enum inside or outside of the class] |
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 SATURDAYEnumOutsideDemo.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 SATURDAYClick the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/EnumDemo_define_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/EnumDemo_define_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/4ee0c57df034098ab5ebc06d5a6296fa5950097a/BasicJava/EnumDemo_define_App/?at=master
See also:
No comments:
Post a Comment