刷题的错题记录

class A {

public A(){

System.out.println("A");

}

}

class B extends A{

public B(){

System.out.println("B");

}

public static void main(String[] args) {

B b=new B();

}

}

执行的结果是通过编译输出B

static方法可以处理非静态属性 错误 

yield不会使线程进行阻塞状态。

sleep是线程类(Thread)的方法,wait是Object类的方法 对

Sleep不释放对象锁,wait放弃对象锁 对

Sleep暂停线程、但监控状态任然保持,结束后会自动恢复 对

Wait后进入等待锁定池,只针对此对象发出notify方法后获取对象锁进入运行状态。 错误 

下列锁机制不可以保证线程安全的是  Volatile

interface Inter {
void show();//注意:这里的void show();语句的前面其实有修饰符,应该为public abstract void show();

}

class Outer {

public static Inter method() {

return new Inter() {

  public void show() {

   System.out.println("HelloWorld");

  }

 };

}

}

class OuterDemo {

public static void main(String[] args) {

 Outer.method().show();

}

}

Java中所有带缓冲机制的类的默认缓冲大小是多少? 521MB

fail-fast 是什么?

快速失败是java集合中的一种机制,在用迭代器遍历一个集合对象时,如果遍历过程对集合对象的内容进行了修改(增加,删除,修改),则会抛出Concurrent modification exception。

场景: java.util 包下的集合类都是快速失败的,不能在多线程下发生并发修改(迭代过程中被修改)算是一种安全机制。

HashTable和HashMap的区别?

  • HashTable是不允许建或值为null, HashMap键值都可为null
    实现方式不同,hashtable继承了dictionary类, hashmap继承abstractmap类
    初始化容量不同,hashmap的初始化容量为16, hashtable的初始化容量为11,两者的负载因子默认都是0.75
    扩容机制不同,当现有容量大于总容量*负载因子时,hashmap扩容规则为当前容量翻倍, hashtable扩容规则为当前容量翻倍+1
    迭代器不同,hashmap中的Iterator迭代器是fail-fast的,而hashtable的Enumerator不是。
     

    以下代码输出结果:

  • public class Test {
        private String msg="hello world";
        public static void haha(){
            System.out.println("haha");
        }
    
        public static void main(String[] args) {
            Test test=new Test();
            test.msg="hougeisgood";
            test.msg=null;
    
            System.out.println(test.msg);
        }
    }
    

    null

以下代码执行结果:

public class Null {
    public static void haha(){
        System.out.println("haha");
    }

    public static void main(String[] args) {
        Null null1=new Null();
        ((Null)null).haha();
        haha();
        null1.haha();
    }
}

三个haha

猜你喜欢

转载自blog.csdn.net/houzhicongone/article/details/120226136