## API (a) ---- enumeration

enumerate

## First, the definition:

  Starting java SE 5.0, java programming language introduces a new type - enumeration (Enum).

## Second, the concept:

  It refers to the type enumerated by a group consisting of fixed constants, enum defined keyword.

## Third, the syntax:

  [Modifier] enum enumName{

    enumContantName1,[enumContantName2]

  }

  Modifier  is access modifier, such as public and so on.

  enum keyword.

  enumContantName1  represent enumeration constants list, separated by commas between.

Note: in the enumeration, if in addition to define the enum constant defines additional members, the enumerator constant list must be separated by a semicolon.

## four, exemplified

The definition of an enumeration, enumeration constants, including seven, seven days a week on behalf of, became achieve the look of the week daily schedule

 

Public  enum Week { 
    Mon, Tue, Wed, Thu, Fri, SAT, Sun 
}

 

public  class the doWhat {
     public  void daWhat (Week Day) {
         Switch (Day) {
             Case MON:
             Case TUE:
             Case WED:
             Case THU:
             Case FRI: 
                System.out.println ( "! workdays trying to write code" );
             Case SAT : 
                System.out.println ( "Saturday, rest, watch a movie!" );
             Case SUN: 
                System.out.println ( "! Sunday, rest, play basketball" );
                 default :
                    System.out.println ( "God! 7 only one week on the earth" ); 
        } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/liurui-bk517/p/11088094.html