错题记录1

1、多个线程可同时操作一个数据,为了保证该数据的准确性,可将操作该数据的部分改为()

A同步,B异步,C只读,D只写

答案:A

对该数据加锁,放在同步代码块中
synchronize(){
}

2、 以下描述正确的是

CallableStatement是PreparedStatement的父接口

PreparedStatement是CallableStatement的父接口

CallableStatement是Statement的子接口

PreparedStatement是Statement的父接口

答案:B

public interface CallableStatement extends PreparedStatement
public interface PreparedStatement extends Statement
3、x>>3代表X右移三位。
4、
A,Vector相当于一个线程安全的List
B,HashMap是非线程安全的,其对应的线程安全类是HashTable
C,Arraylist是非线程安全的,其对应的线程安全类是Vector
D,StringBuffer是线程安全的,相当于一个线程安全的StringBuilder
E,Properties实现了Map接口,是线程安全的
 

5、下面代码的输出是什么?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class Base
{
    private String baseName = "base";
    public Base()
    {
        callName();
    }
 
    public void callName()
    {
        System. out. println(baseName);
    }
 
    static class Sub extends Base
    {
        private String baseName = "sub";
        public void callName()
        {
            System. out. println (baseName) ;
        }
    }
    public static void main(String[] args)
    {
        Base b = new Sub();
    }
}
 
 
答案:输出null
 
new Sub();在创造派生类的过程中首先创建基类对象,然后才能创建派生类。
创建基类即默认调用Base()方法,在方法中调用callName()方法,由于派生类中存在此方法,则被调用的callName()方法是派生类中的方法,此时派生类还未构造,所以变量baseName的值为null
 
原文地址:https://www.cnblogs.com/chenxing818/p/4664137.html