面试题(基础)
- == 与 equals 的区别
- hashMap原理, 与HashTable的区别,有没有兼顾两者优点的类
- 写出下面代码的输出结果,并解释原因:
1 2
| String str0 = null;
String str1 = "Tomcat";
String str2 = "Tom" + "cat";
String str3 = new String("Tomcat");
System.out.println(str1 == str2);
System.out.println(str1 == str3);
System.out.println(str1 == str3.intern());
System.out.println(str1.equals(str2));
System.out.println(str0 == str1);
System.out.println(str0.equals(str1));
|
1
| public class Device extends Base {
private String name = "dervied";
public Device() {
tellName();
printName();
}
public void tellName() {
System.out.println("Dervied tell name: " + name);
}
public void printName() {
System.out.println("Dervied print name: " + name);
}
public static void main(String[] args) {
new Device();
}
}
class Base {
private String name = "base";
public Base() {
tellName();
printName();
}
public void tellName() {
System.out.println("Base tell name: " + name);
}
public void printName() {
System.out.println("Base print name: " + name);
}
}
|
- 手写线程安全的单例模式
- 深拷贝与浅拷贝场景,哪些方法是浅拷贝。如何实现深拷贝。