枚举类型

来源:互联网 发布:excel2013数据分级显示 编辑:程序博客网 时间:2024/06/05 03:22

1 对于“It is account type” 和FIXED的输出次数正确的是( )

enum AccountType{

SAVING,FIXED,CURRENT;private AccountType(){    System.out.println("It is a account type"); }

}
public class Test1 {

public static void main(String[] args) {    System.out.println(AccountType.FIXED);}

}

A 1 1
B 2 1
C 3 1
D 2 2

注解:枚举类型的每一个属性都会映射到构造函数中, 即就是说,枚举的每一个属性都会调用一次构造函数, 特别
* 注意,枚举的构造函数都是私有的, 枚举值是静态常量, 在初始化的时候,会对枚举值进行一次初始化,
2 下列输出的结果正确的是()
public class Test2 {

public static void main(String[] args) {    String str1 = "hello";    String str2 = "he" + new String("llo");     System.err.println(str1 == str2);    System.out.println(str1.equals(str2));}

}
A true false
B false true
C true true
D false true
注解: err 和 out 的区别: err 颜色是红色的,err是错误输出 , out 是标准输出
* str1 指向的是方法区的常量池中
* str2 指向的是堆上申请的内存。

0 0
原创粉丝点击