String str=new String("JAVA");
System.out.println("value of str before "+str); //JAVA
String str2=null;
str=str2;
System.out.println("value of str"+str); //null
System.out.println("value of str2"+str2);//null
str="Prog";
System.out.println("value of str"+str); //prog
System.out.println("value of str2"+str2);//null
質問 1 文字列が不変の場合、なぜ str の値が変化するのですか??
Student stu= new Student(123);
System.out.println("value of stu before "+stu); //some address is printed
Student stu2=null;
stu=stu2;
System.out.println("value of stu"+stu); //null
System.out.println("value of stu2"+stu2);//null
Student stu3=new Student(456);
stu=stu3;
System.out.println("value of stu"+stu); //some new address
System.out.println("value of stu2"+stu2);//null
Ques 2.String と Object は同じように動作します。では、なぜ String は不変で Object は可変なのか。どこが違うの