一个枚举类型是不能extends任何类或另一个枚举类型的。但是可以实现一个或多个接口。例如
<!---->package implinterface;
public interface Abbrevable
{
String abbrev();
}
<!---->package implinterface;
public interface Multiplierable
{
double multiplier();
}
<!---->package implinterface;
public enum Prefix implements Abbrevable, Multiplierable
{
// These are the values of this enumerated type.
// Each one is followed by constructor arguments in parentheses.
// The values are separated from each other by commas, and the
// list of values is terminated with a semicolon to separate it from
// the class body that follows.
MILLI("m", .001),
CENTI("c", .01),
DECI("d"),
DECA("D", 10.0),
HECTA("h", 100.0),
KILO("k", 1000.0); // Note semicolon
// semicolon
// This is the constructor invoked for each value above.
private Prefix(String abbrev, double multiplier)
{
this.abbrev = abbrev;
this.multiplier = multiplier;
}
//Another constructor
private Prefix(String abbrev)
{
this.abbrev = abbrev;
this.multiplier = .1;
}
// These are the private fields set by the constructor
private String abbrev;
private double multiplier;
// These are accessor methods for the fields. They are instance methods
// of each value of the enumerated type.
public String abbrev()
{
return abbrev;
}
public double multiplier()
{
return multiplier;
}
}
<!---->package implinterface;
public class TestPrefix
{
public static void main(String[] args)
{
Prefix p = Prefix.MILLI;
System.out.println(p.abbrev());
System.out.println(Prefix.class);
}
}
分享到:
相关推荐
java枚举类型详细讲解,自己撰写的一本电子书,编写得很详细
USB枚举过程 USB Enumeration
Java 核心技术 卷1 Index Chapter 1: An Introduction to Java 1 Java As a Programming Platform 2 The Java “White Paper” Buzzwords 2 Java Applets and the Internet 7 A Short History of Java 9 ...
Iterator与Enumeration分别是实现迭代器和枚举器类的接口,下面就带大家来详解Java中的迭代迭代器Iterator与枚举器Enumeration,以及它们之间的区别.
swift代码-class类和Enumeration枚举的使用
linux-smart-enumeration-master.zip
Java 实例 - 使用 Enumeration 遍历 HashTable源代码+详细指导教程.zip
Access-based Enumeration Windows Server 2003安装包
NULL 博文链接:https://chaoyi.iteye.com/blog/2085158
小小的列举进程程序可以把他列举出来,这个是源码
enum的全称为enumeration, 是 JDK 1.5中引入的新特性,存放在 java.lang包中。下面这篇文章是我在使用enum过程中的一些经验和总结,分享出来方便大家快速的掌握Java中枚举(enum),有需要的朋友们下面跟着小编来一起...
首先,几个有用的oneliners;... 用于渗透测试和CTFLinux枚举工具 该项目的灵感来自并使用了许多测试。 不像LINENUM, lse尝试gradualy揭露根据其重要性从一个privesc点的信息。 它是什么? 该She
Laravel的简单,可扩展和强大的枚举实现。 枚举键值对作为类常量 功能齐全的方法套件 枚举实例化 标记/按位枚举 类型提示 属性转换 枚举工匠生成器 将枚举键或值作为输入参数传递的验证规则 本地化支持 可通过宏...
第10章 结构体和共用体——枚举类型C语言程序设计第10章 结构体和共用体枚举标签枚举数据类型枚举(Enumeration)——一一列举应用场合当某些量仅由有限
Java类集框架 最大单值操作父接口Collection及其子接口、子类: List接口、ArrayList类、Vector类、栈操作类Stack、链表操作类LinkList、队列操作接口Queue、Set接口、HashSet类、TreeSet类、SortedSet接口 双值操作...
扫描和枚举自动化工具SEA安装打开终端通过输入命令来创建虚拟环境:python3 -m venv SEA 通过输入以下命令激活虚拟环境:source SEA / bin / activate 使用以下命令安装python库:pip3 install -r requirements.txt ...
亚信18年java笔试题 hack-er-tools:应急响应工具包 USE AT YOUR OWN RISK! 工具/资源皆来源于网络 部分工具较大,只提供下载链接 欢迎大家补充和推荐! pdf下载: 应急响应指南: 目录 AV(av/) clamav.tar.gz:...
本文将介绍J2SE5.0中三个比较重要的...这些特性包括范型(generics)的支持,枚举类型(enumeration)的支持,元数据(metadata)的支持,自动拆箱(unboxing)/装箱(autoboxing),可变个数参数(varargs),静态导入(staticimports),