Java Enumeration (ii): That is, the example in the Java enumeration (a) to expand

Source: Internet
Author: User

/* Knowledge Points: Enumerations      enumerations are a new type of data that is provided starting from Java5, a special class, which is the collection definition format for multiple constant objects:     [modifier]  enum  enum class name     {         constant a,  constant B,   Constants c;    }*///Define enumeration Enum weekday{    monday, tuesday,  wednesday, thursday, friday, saturday, sunday;    // The Monday in the enumeration type is equivalent to the original: Public static final weekday monday = new weekday ();} class employees{    private weekday restday; //which day of the week is rested (data type Weekday)     public weekday getrestday ()     {         return restday;    }    public void  setrestday (weekday restday)  //data type is weekday    {         this.restday = restday;    }}public class enumerateexample{     Public static void main (String[] args)      {         employees e = new employees ();  //Create an Employee object          e.setrestday (weekday.wednesday);  //set the break time by the class name, object,          weekday restday = e.getrestday ();  // Receive values with variable restday of type weekday                  if (restday == weekday.saturday | |  restday == weekday.sunday)         {             system.out.println ("Weekend break ...");         }        else        {             System.out.println ("Monday to Friday Rest ...");         }    }}/* Weekday byte-code file contents (post-compilation with Java bytecode counter-compile tool): final class weekday extends enum // The custom Weekday enumeration class is inherited from the Java.lang in the underlying enum{    public static final weekday  monday;    public static final weekday tuesday;     public static final weekday wednesday;    public static  final weekday thursday;    public static final weekday  Friday;    public static final Weekday Saturday;     public static final weekday sunday;    private static  final Weekday  $VALUES [];     public static weekday[] values ()     {         return  (weekday[]) $VALUES. Clone ();    }     public static weekday valueof (string s)     {         return  (Weekday) enum.valueof (weekday, s);     }    private weekday (string s, int i)     {         super (s, i);    }     static     {        Monday =  New weekday ("Monday",  0);         tuesday = new  weekday ("Tuesday",  1);         wednesday = new  weekday ("Wednesday",  2);         thursday = new weekday ("Thursday",  3);         friday = new weekday ("Friday",  4);         saturday = new weekday ("Saturday",  5);         sunday = new weekday ("Sunday",  6);          $VALUES  =  (new weekday[] {             Monday, Tuesday, Wednesday, Thursday,  friday, saturday, sunday        });     } }*/


Java Enumeration (ii): That is, the example in the Java enumeration (a) to expand

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.