str2=str1,用的是值调用,并非别名调用,str2不随str1的改变而改变如果你用别名调用,那么输出str2就是“this is a test modified string!”

解决方案 »

  1.   

    String是个类型骗子,String不是基本型,但是却实现了基本型的传递!
      

  2.   

    程序运行到:str2=str1时,
    str1,str2都是reference,指向:this is a test string!对象
    使用:str1="this is a test modified string!";
    即:申明str1指向了另一个对象"this is a test modified string!",而str2不变
    所以输出的str2为何是“this is a test string!”参考:
    http://www.csdn.net/develop/Read_Article.asp?Id=22025
      

  3.   

    class string{
    public static void main(String args[]){
    StringBuffer str1=new StringBuffer("this is a test string!");
    StringBuffer str2;
    str2=str1;
    str1=str1.append("this is a test modified string!");
    System.out.println(str2);
    }
    }
    就可,正如hyhu(先飞笨鸟) 所说: 
    String是个类型骗子,String不是基本型,但是却实现了基本型的传递!
      
     
      

  4.   

    java的强项在于它的安全性,特别适合于网络开发。
      

  5.   

    当str1="this is a test modified string!";
    前面的str1已经销毁!!!
    String类的学问大了!!!
      

  6.   

    赞同lyjlee() 的看法,str2=str1句使得这两个变量指向同一地址空间,
    但当你再次赋值之后:str1="this is a test modified string!";
    str1所指向的是一个新的地址空间,此时 str1和str2是不想等的.
      

  7.   

    看见四个星星,好羡慕!
    ----------------------------------------------------------------------------------
    class string{
    public static void main(String args[]){
    String str1="this is a test string!";
    String str2;
    str2=str1;
                      //str2等于"this is a test string!"
    str1="this is a test modified string!";
    /* str2还是等于"this is a test string!",因为当str1被赋予新值后,其值没有赋予str2,所以str2还是保持原值。*/
    System.out.println(str2);
    }
    }
    ----------------------------------------------------------------------------------前面几位已经解答清楚了!
      

  8.   

    同意 上面的
    如果A=B
    如果你修改了B 那么A是不会改变的类似str1=str2
      

  9.   

    现在又有点糊涂了,不知道到底java到底是值传递还是地址传递。
      

  10.   

    Java是完全面向对象的.
    J2SE是基础.
    J2EE:用于企业级开发.
    J2ME:用于小型移动设备.
      

  11.   

    同意lyjlee()的说法。
    过程执行。
      

  12.   

    str2指的是str1的值,而非str1的地址。你应该应用str1,把str2的指针指向str1的地址。
    不应该把str1的值直接赋给str2.
      

  13.   

    lyjlee() 的第1个帖子已经说清楚了原因