题(一)enum AccountType

简介: what is the result of the following code?enum AccountType { SAVING, FIXED, CURRENT; private AccountType() { System.

what is the result of the following code?

enum AccountType
{
SAVING, FIXED, CURRENT;
private AccountType()
{
System.out.println(“It is a account type”);
}
}
class EnumOne
{
public static void main(String[]args)
{
System.out.println(AccountType.FIXED);
}
}

Compiles fine and output is prints”It is a account type”thrice followed by”FIXED”

枚举类有三个实例,故调用三次构造方法,打印三次It is a account type

这里写图片描述

创建枚举类型要使用 enum 关键字,隐含了所创建的类型都是 java.lang.Enum 类的子类(java.lang.Enum 是一个抽象类)。枚举类型符合通用模式Class Enum

目录
相关文章
|
4月前
|
C语言
C enum(枚举)
C enum(枚举)
30 0
|
3月前
|
存储 安全 API
C++一分钟之-C++中的枚举类型(enum class)
【6月更文挑战第25天】C++的`enum class`(强类型枚举)在C++11中引入,增强了枚举的作用域和类型安全,减少命名冲突。它要求使用全名(如`Color::Green`)访问枚举成员,并能显式指定底层类型。常见问题包括默认值非0、隐式转换和范围溢出,解决办法是明确赋值、显式转换和选择合适底层类型。高效技巧包括用于状态机、作为函数参数、创建别名和迭代。掌握这些能提升代码质量。
96 0
|
4月前
|
程序员 C语言
c enum(枚举)
c enum(枚举)
45 1
|
4月前
|
程序员 测试技术 C++
[C++] enum枚举类型用法
[C++] enum枚举类型用法
71 0
Enum
Enum
95 0
|
JavaScript C#
enum:枚举类型
enum:枚举类型
170 0
|
Java C语言 Spring
enum(枚举)
枚举是 C 语言中的一种基本数据类型,它可以让数据更简洁,更易读。
228 0
|
程序员 网络安全 C++
C/C++ enum使用
C/C++ enum使用
203 0
|
安全 C# 存储