我的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)

          相冊

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 北安市| 寻乌县| 隆安县| 久治县| 古浪县| 梁山县| 惠来县| 伊金霍洛旗| 敖汉旗| 黄浦区| 宜丰县| 黄冈市| 金阳县| 丰都县| 永年县| 疏附县| 盱眙县| 侯马市| 女性| 惠水县| 双桥区| 耒阳市| 溧水县| 吉木萨尔县| 汤原县| 申扎县| 台江县| 黄浦区| 麻阳| 隆子县| 如皋市| 长宁县| 前郭尔| 蚌埠市| 衡阳市| 龙州县| 龙陵县| 贞丰县| 军事| 建宁县| 永泰县|