Friday, 5 May 2017

Java Tutorial: Enum in java[How to define a constructor in enum]

Click here to watch in Youtube :

Click the below Image to Enlarge
Java Tutorial: Enum in java[How to define a constructor in enum]
public class EnumDemo

    private enum Day

        private int whichDay;

         * Constructor of enum type is private. If you don't
         * declare private compiler internally creates
         * private constructor.
        private Day(int whichDay)
            this.whichDay = whichDay;


    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 + " is which day? " + day.whichDay);

MONDAY is which day? 1
TUESDAY is which day? 2
WEDNESDAY is which day? 3
THURSDAY is which day? 4
FRIDAY is which day? 5
SATURDAY is which day? 6
SUNDAY is which day? 7
Click the below link to download the code:

Github Link:

Bitbucket Link:

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge