// Static import: import the static method in this class <br/> Import static Java. lang. system. out; </P> <p>/** <br/> * simple examples of enumeration classes. <br> <br/> * @ author he Shaohui. <br> <br/> * Create 2010-07-19. <br/> */<br/> public class testenum {</P> <p> Public static void main (string [] ARGs) {<br/> // obtain all enumeration objects <br/> SEASON2 [] Ss = season2.values (); <br/> for (SEASON2 S: SS) {<br/> out. println (S. ordinal () + "--->" + S. name (); <br/>}< br/> // obtain a single enumerated object. <br/> Season1 S = enum. valueof (season1.class, "Spring"); <br/> SEASON2 S2 = season2.spring; <br/> // application instance <br/> // 1: addition, subtraction, multiplication, and Division <br/> operator [] OP = Operator. values (); <br/> for (operator O: op) {<br/> out. println (O. getname () + "(" + O. name () + "):" + O. calculate (4, 2); <br/>}< br/> // 2: Switch case <br/> string action = ""; <br/> switch (season1.valueof (Action) {<br/> case AUTUMN: <br/> break; <br/>}</P> <p> // The simplest enumeration definition. <br/> Enum Season1 {<br/> spring, <br/> summer, <br/> autumn, <br/> Winter; <br/>}</P> <p> Enum SEASON2 {<br/> spring ("Spring"), <br/> summer ("Summer "), <br/> autumn ("Autumn"), <br/> Winter ("Winter"); <br/> // attributes can be set by the constructor and set methods. <br/> private string name; <br/> private string age; <br/> private SEASON2 (string name) {<br/> This. name = Name; <br/>}< br/> Public String getname () {<br/> return this. name; <br/>}< br/> Public void setage (string age) {<br/> This. age = age; <br/>}< br/> Public String getage () {<br/> return this. age; <br/>}</P> <p> Class A {}< br/> // Enum season3 extends a {}// error enumeration cannot inherit one class <br/> // Class B extends SEASON2 {}// error class cannot inherit an enumeration <br/> interface Ia {<br/> Public void print (); <br/>}</P> <p> // enumeration implementation interface: 1: The interface method is implemented by the enumeration object. 2: enumeration objects can be implemented without interfaces. 3: When an external call is not implemented, no error is reported. <br/> Enum season3 implements Ia {<br/> spring {<br/> Public void print () {<br/>}< br/> }, <br/> summer, <br/> autumn, <br/> Winter; <br/> Public void print () {}< br/>}</P> <p> Enum operator {<br/> Add ("plus") {<br/> Public int calculate (int I, int J) {<br/> return I + J; <br/>}< br/>}, <br/> minus (" ") {<br/> Public int calculate (int I, Int J) {<br/> return I-j; <br/>}< br/> }, <br/> multiply ("multiplication") {<br/> Public int calculate (int I, Int J) {<br/> return I * J; <br/>}< br/>}, <br/> divide ("except") {<br/> Public int calculate (int I, Int J) {<br/> return I/J; <br/>}< br/>}; <br/> private string name; <br/> private operator (string name) {<br/> This. name = Name; <br/>}< br/> Public String getname () {<br/> return this. name; <br/>}< br/> public abstract int calculate (int I, Int J); <br/>}</P> <p>