zoukankan      html  css  js  c++  java
  • java基础---->Java中枚举的使用(一)

      这里介绍一下java中关于枚举的使用。

    java中枚举的使用

    一、枚举中可以定义方法

    参照于TimeUnit的使用,TimeUnit.MILLISECONDS.sleep(1000);

    • LoveUtils的类:
    package com.linux.huhx.enumTest;
    
    /**
     * Created by huhx on 2017-05-24.
     */
    public enum LoveUtils {
        BOYS {
            public String getName() {return "huhx";}
            public String getPassword() {return "123456";}
        },
        GRIL {
            public String getName() {return "linux";}
            public String getPassword() {return "654321";}
        };
    
        public String getName() {
            throw new AbstractMethodError();
        }
    
        public String getPassword() {
            throw new AbstractMethodError();
        }
    
        public void sayHello() {
            String name = getName();
            System.out.println("my name is " + name + ", and password: " + getPassword());
        }
    }
    • 测试的EnumTest1类代码:
    package com.linux.huhx.enumTest;
    
    /**
     * Created by huhx on 2017-05-24.
     */
    public class EnumTest1 {
        public static void main(String[] args) {
            LoveUtils.BOYS.sayHello(); // my name is huhx, and password: 123456
            LoveUtils.GRIL.sayHello(); // my name is linux, and password: 654321
        }
    }

    友情链接

  • 相关阅读:
    POJ3040--Allowance(贪心)
    Deep work
    湾区公司上班第一周
    三个现场面试
    协商薪资
    调节情绪,精神愉悦,健康快乐
    Phone interview guide 多说
    Campus Bikes
    降低软件复杂度 和 写注释写总结 2019-10
    某厂在线测试 2019.09.26
  • 原文地址:https://www.cnblogs.com/huhx/p/baseusejavaenum1.html
Copyright © 2011-2022 走看看