如题

解决方案 »

  1.   

    public final class String implements java.io.Serializable, Comparable<String>, CharSequence你看看它实现了什么接口?
      

  2.   

    public final class String
    extends Object
    implements Serializable, Comparable, CharSequence
      

  3.   

    没有进行深拷贝,是你理解错了。再仔细想想,看自己卡在那里了。
    String其实是个常量类型,他的任何一个对象都是不变的,它的所有的方法也是顶多返回一个新的串给你,而自身是永远不变的。
    如果还想不明白,把你不明白的代码贴出来,让大家帮你解释解释。:)
      

  4.   

    String类型的构造方法没有说深拷贝实现克隆方法的类你都可以构造出一个和原来实例状态一模一样的对象,而String继承自Object的clone方法在Object中也好像只是克隆了一下对象的地址,而String也并没有重写这个方法,这就可以说明,string并没有打算用这个clone方法不知道1.5中的String是不是另外一个样子
      

  5.   

    //:StringTest.java
    class Student implements Cloneable
    {
       private String name ;
     private String num;

     public Student(String name , String num)
     {
        this.name = name;
        this.num = num;
     }
     
     public Student modify(String name)
     {
        this.name =name;
        return this;
     }
     
     public String toString()
     {
        return name + " "+num ;
     }

    public class StringTest
    {
      public static void test(String str)   
    {
       str  = str + " World!";
    }
    public static void test(Integer str)   
    {
       Integer inte= str;
        inte = new Integer(100);
    }
    public static void test(Student stu)   
    {
       stu  = stu.modify("zeiku");
    }
    public static void main(String []args)
    {
    String str = new String("Hello");
      test(str);
      prt(""+str);
      
      Integer inte = new Integer(1000);
      test(inte);
      prt(""+inte.intValue());
      
      Student stu = new Student("zhudonhua","3030612060");
      test(stu);
      prt(""+stu);
    }
    public static void prt(String str)
    {
    System.out.println(str);
    }
    }
    看看,这是为什么???
      

  6.   

    class Student
    {
       private String name ;
       private String num;
       public Student(String name , String num)
        {
     this.name = name;
     this.num = num;
        }
     
       public Student modify(String name)
       {
     this.name =name;
     return this;
       }
     
       public String toString()
      {
     return name + " "+num ;
      }

    public class StringTest
    {
      public static void test(String str)   
       {
          str  = str + " World!";
       }
      public static void test(Integer str)   
       {
    str = new Integer(100);
       }
      public static void test(Student stu)   
      {
     stu  = stu.modify("zeiku");
      }
      public static void main(String []args)
      {
     String str = new String("Hello");
     test(str);
     prt(""+str);
      
     Integer inte = new Integer(1000);
     test(inte);
     prt(""+inte.intValue());
      
     Student stu = new Student("zhudonhua","3030612060");
     test(stu);
     prt(""+stu);
       }
    public static void prt(String str)
    {
    System.out.println(str);
    }
    }我自己定义一个类,但是他打印出的结果?????
    运行结果:
    Hello
    1000
    zeiku 3030612060
    为什么最后一行不是zhudonhua 3030612060??????
      

  7.   

    public static void test(Student stu)
    {
    stu = stu.modify("zeiku");
    }你在这里不是已经把name改了吗?
      

  8.   


    Hello
    1000
    为什么不变啊??
    我在
      public static void test(String str)   
       {
          str  = str + " World!";
       }
      public static void test(Integer str)   
       {
    str = new Integer(100);
       }
    也改了啊!!!
      

  9.   

    str = str + " World!";
    这句是改变了参数str引用的对象,这句执行完以后,str引用到一个新对String对象,而并非改变了str原来所引用的那个对象的内容。而又因为局部修改参数引用并不影外部的调用者,所以外面原来的那个变量名(引用)还是引用着它原来引用的那个String对象"Hello"。
    str = new Integer(100);
    一样的道理,里面修改了引用,不影响外面那个引用本来所引用的对象。如果楼主熟悉C语言的指针,理解这些东西应该很容易。
      

  10.   

    还有,引用传递的许多特性在String和Integer这两个类的对象上是看不出来的,如果你仔细研究一些这两个类的所有方法,你会发现,这两个类都是那种“常量类”,你可以获得它里面的数据,你也可以利用他们构造新的数据,但就是无发改变他们里边的任何东西。
    这就是为什么你可以通过:
    str = str + "World";
    来利用原来str所引用的对象再加“World”一起构造一个新对象并让str引用到这个新对象,却无法改变原来那个str所引用的对象本身。
    但StringBuffer类可以,这个类有许多可以改变自己的函数。