我的java天地

          枚舉示例程序

          ?

          ?1 public ? class ?EnumTest? {
          ?2

          ?3 ???? public ? enum ?MsgType?
          {
          ?4 ????????SMS( " this?sms " ),?LONGSMS( " this?is?longsms " ),?MMS( " this?is?mms " ),?WAP_PUSH( " this?is?wap?push "
          );
          ?5 ???????? private ? final
          ?String?index;
          ?6

          ?7 ???????? private ?MsgType(String?index)?
          {
          ?8 ???????????? this .index? =
          ?index;
          ?9 ????????}

          10
          11 ????????
          /* public?int?getIndex()?{
          12
          ????????????return?index;
          13 ????????} */

          14
          15 ???????? // 下面這段基本上不用

          16 ???????? public ? static ?MsgType?getType( int ?index)? {
          17 ???????????? switch ?(index)?
          {
          18 ???????????? case ? 0
          :
          19 ???????????????? return
          ?SMS;
          20 ???????????? case ? 1
          :
          21 ???????????????? return
          ?LONGSMS;
          22 ???????????? case ? 2
          :
          23 ???????????????? return
          ?MMS;
          24 ???????????? case ? 3
          :
          25 ???????????????? return
          ?WAP_PUSH;
          26 ???????????? default
          :
          27 ???????????????? return
          ?SMS;
          28 ????????????}

          29 ????????}

          30 ????}

          31 ????
          32
          ????
          33 ???? public ? static ? void ?main(String?[]args)
          {
          34
          ????????System.out.println(MsgType.SMS);
          35 ????????System.out.println(MsgType.getType( 0
          ));
          36 ????}

          37 }

          38

          posted on 2011-05-23 15:43 tobyxiong 閱讀(250) 評論(0)  編輯  收藏 所屬分類: java

          <2011年5月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          導航

          統計

          常用鏈接

          留言簿(3)

          隨筆分類(144)

          隨筆檔案(157)

          相冊

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 永春县| 特克斯县| 靖边县| 丰镇市| 尼木县| 武宁县| 黔江区| 施甸县| 秦皇岛市| 阳原县| 沙坪坝区| 定结县| 融水| 太原市| 子洲县| 磴口县| 长葛市| 嘉善县| 樟树市| 武夷山市| 砀山县| 津南区| 法库县| 吴忠市| 县级市| 辽源市| 杂多县| 博白县| 阿图什市| 五华县| 辽宁省| 张家界市| 新闻| 陇川县| 观塘区| 通化县| 广平县| 南昌市| 图们市| 兴和县| 屏东县|