Package CN. itcast. day1;
Public class Enum {
Public static void main (string [] ARGs ){
Weekday1 weekday = weekday1.sat;
System. Out. println (weekday. nextday ());
System. Out. println (weekday. Fri );
System. Out. println (weekday. Mon. Name ());
System. Out. println (weekday. Mon. ordinal ());
}
Public Enum weekday {
// Simple enumeration
Sun, Mon, Tus, wed, Thu, Fri, SAT; // you can add a; number or no
// Enumeration with Constructor
// When enumeration has a constructor, 1. The constructor must be placed behind the attribute.
// 2. The attribute must be followed by a; No.
// 3. The constructor must be private.
// Construction method without Parameters
Private weekday (){}
// Construction method with Parameters
Private weekday (INT day ){}
}
Public Enum trifficlight {
// Enumeration with abstract methods
Green (30 ){
Public trifficlight nextlight (){
Return yellow;
}
},
Red (15 ){
Public trifficlight nextlight (){
Return green;
}
},
Yellow (5 ){
Public trifficlight nextlight (){
Return red;
}
};
// The next light is
Public abstract trifficlight nextlight ();
// Define a construction method with Parameters
Private int time; // the time when each lamp is on.
Private trifficlight (INT time ){
This. Time = time;
}
}
}