new 出来的对象都会放到堆里面,所以只有一个? 错了!!!
1,String 对象是final的,是不能继承的,为啥是final的??? 够完美了 所以不用继承了吧。。。
2,会在堆里创建一个引用对象,“Hello” 会放到常量池中,所以在常量池中也会创建一个对象;
综上:会创建两个对象;
3.
String a = "hello";
String b ="hello";
System.out.println(a==b) 为True; hello放在运行时常量池中,只会存在一份,所以b定义时候回先去常量池中找值是否存在,如果存在则直接指向它;
4.
String c = new String("hello");
System.out.println(a==c) 为false; 此时的 c 会先在堆里面创建一个引用对象,所以为false;
5.
String str2 = "hello";String str3 = "hel"; String str4 = "lo"; String str5 = str3+str4; System.out.println(str2==str5); false