enuminclass.java

来自「Java面向对象编程(随书配套源代码) 阐述了面向对象编程的思想」· Java 代码 · 共 39 行

JAVA
39
字号
package chapter7;
public class EnumInClass 
{
	private  int i =0;
	public  enum Month  //只允许使用存取修饰符、static、abstract
	{
	   January("Jan") ,February("Feb"),March("Mar"),April("Apr"),May("May"),
	   June("June"),July("July"),August("Aug"),September("Sept"),October("Oct"),November("Nov"),December("Dec");
	   
	   public String abbreviation = "";
	   Month(String abbreviation) //枚举构造函数只能private,默认也为private
	   {
		   this.abbreviation = abbreviation;
	   }
	   
	   public static void display()
	   {
		   for(Month m : Month.values())
		   {
		       System.out.println(m.ordinal() +" " + m.abbreviation);
		   }
	   }
	   public void out()
	   {
		   System.out.println(this.abbreviation);
	   }
	   
	}	
	public static void display()
	{
		Month.display();
	}
	public static void main(String args[])
	{
		EnumInClass.display();
		Month.April.out();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?