String s = "abc";
这里采用的是一种特殊类型:字串可用加引号的文字初始化。通常,必须为对象使用一种更通用的初始化类型。String s = new String("asdf");
它不仅指出“将我变成一个新字串”,也通过提供一个初始字串,指出了“如何生成这个新字串”。

解决方案 »

  1.   

    两个对象一个是abc 另一个是 a
      

  2.   

    String s = "abc";
    "abc"是内存堆中一个已经存在的对象,这个是声明用s指向这个对象。String s = new String("abc");
    "abc"是内存堆中一个已经存在的对象,有没有引用指向它并不知道;这个语句通过new关键字,生成了一个与"abc"对象内容一致的另一个对象(即拷贝了一份),新生成的这个对象用s指向。API中的解释:
    String(String original) 
              Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.
      

  3.   

    s是一个变量,或者一个string对象,它的初始化方法是一个指针,或者说赋值语句是通过指针来实现的,但是不能说s就是一个指向abc的引用
      

  4.   

    String a=nwe String("abc"); 中,我认为只是生成一个对象abc,a只是一个指向“abc”地址的引用,即它只是一个变量名。
    而String a="abc";中,由于String是个特殊的类,java编译器遇到带双引号的字符串时,就会自动生成一个实例其实和String a=nwe String("abc"); 是一样的。
      

  5.   

    还有人有没有更精辟的解释
    我觉得DanaLiu说的很有道理
      

  6.   

    同意DanaLiu所说的。yinleiyoung(星际孤虹) 其实也是同一个意思。。