1.下面有关java hashmap的说法错误的是?(C)
A.HashMap 的实例有两个参数影响其性能:“初始容量” 和 “加载因子”。
B.HashMap 的实现不是同步的,意味着它不是线程安全的
C.HashMap通过开放地址法解决哈希冲突
D.HashMap中的key-value都是存储在Entry数组中的
解析:hashmap采用拉链法解决冲突
2.(C)
public class Testa
{
public int x;
public static void main(String []args)
{
System. out. println("Value is" + x);
}
}
A.程序会打出 “Value is 0”
B.程序会抛出 NullPointerException
C.非静态变量不能够被静态方法引用
D.编译器会抛出 "possible reference before assignment"的错误
解析:静态方法先行执行,导致变量x还未被初始化,所以编译出错
3.
public class NameList
{
private List names = new ArrayList();
public synchronized void add(String name)
{
names.add(name);
}
public synchronized void printAll() {
for (int i = 0; i < names.size(); i++)
{
System.out.print(names.get(i) + ””);
}
}
public static void main(String[]args)
{
final NameList sl = new NameList();
for (int i = 0; i < 2; i++)
{
new Thread()
{
public void run()
{
sl.add(“A”);
sl.add(“B”);
sl.add(“C”);
sl.printAll();
}
} .start();
}
}
}
Which two statements are true if this class is compiled and run?(EG)
A.An exception may be thrown at runtime.
B.The code may run with no output, without exiting.
C.The code may run with no output, exiting normally(正常地).
D.The code may rum with output “A B A B C C “, then exit.
E.The code may rum with output “A B C A B C A B C “, then exit.
F.The code may ruin with output “A A A B C A B C C “, then exit.
G.The code may ruin with output “A B C A A B C A B C “, then exit.
解析:第一次println的字符个数肯定大于等于3,小于等于6;
第二次println的字符个数肯定等于6;所以输出的字符中,后6位肯定是第二次输出的,
前面剩下的就是第一次输出的。而且第一次的输出结果肯定是第二次输出结果的前缀。所以选E、G。
4.
public class Cups {
long length;
public Cups(long l) {
length=l;
}
public static void main(String[] args) {
Cups s1,s2,s3;
s1=new Cups(21L);
s2=new Cups(21L);
s3=s2;
long m=21L;
}
}
下列返回为true的是哪个?(B)
A.s1s2;
B.s2s3;
C.m==s1;
D.s1.equals(m)
解析:A s1和s2在new出来时 会在堆中创建两个对象我们比较s1和s2时是比较他俩的地址 不是他俩的值 地址肯定不一样 一样就是同一个对象了嘛
B.s2和s3进行赋值操作时是把s2和s3都指向同一个堆对象 地址自然一样
CD m在常量池 s1在堆 不能比较 equals中对于对象比较方法也是==
5.下列关于final的数据说法正确的是(D)
A.final定义的数据,不能同时为private
B.final定义的数据,如果同时为static,就不能用private
C.final定义的数据,必须被初始化,而且只能在定义时初始化
D.final定义的数据,必须被初始化,可以在定义时初始化,也可以在构造函数中初始化
解析:
对于AB public static final int a=0 是可以的
CD 可以定义 public final int a;
然后在构造函数中初始化a
6.以下有关类的继承的叙述中,正确的是(D)
A.子类能直接继承父类所有的非私有属性,也可以通过接口继承父类的私0有属性
B.子类只能继承父类的方法,不能继承父类的属性
C.子类只能继承父类的非私有属性,不能继承父类的方法
D.子类不能继承父类的私有属性
解析:官网就是这样说的。