⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 month.java

📁 Java面向对象编程(随书配套源代码) 阐述了面向对象编程的思想
💻 JAVA
字号:
package chapter7;

public  enum Month  //所有枚举值都是public , final,枚举可实现接口
{
   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或友元,
   {
	   this.abbreviation = abbreviation;
   }
   
   public int getOrder(Month m ) //枚举值可作为枚举类型的实例
   {
	   return m.ordinal(); //枚举值作为枚举类型的实例,可直接调用枚举类型中定义的方法
   }
   public static int getEnumSize()
   {
	   return Month.values().length; //返回枚举长度
   }
   public String getAbbreviation( ) 
   {
	   return this.abbreviation;
   }
   public String toString() //枚举类型可定义覆盖方法
   {
	   switch(this)
	   {
	      case January:
	      {
		     return "January";
	      }
	      //……省略其它枚举返回
	      default:
	      {
	    	  return "";
	      }
	   }
   }
   
   
   
}

⌨️ 快捷键说明

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