弱鸡求助,怎么就分析不明白呢?
package practice;public class Testl {
private static int count = 1;
public static void main(String[] args) {
Testl test = new Testl();
String str = "abc";
test.testString(str);
A aA = test.new A(10,"456");
aA.printValues();
test.testRef(aA);
aA.printValues();
aA.a = 50;
test.testRef(aA).printValues();
aA.printValues();
}
public void testString(String str){
String aStr = "abc";
String bStr = "ab" + "c";
String cStr = new String("abc");
System.out.println((count++)+":"+(aStr.equals(cStr))+" "+(aStr==cStr));
System.out.println((count++)+":"+(aStr.equals(bStr))+" "+(aStr==bStr));
}
public A testRef(A aRef){
aRef.printValues();
aRef.str = "ddd";
aRef = new A(20,"987");
aRef.printValues();
return aRef;
}
class A{
private int a = 5;
private String str = "123";
public A(int num,String str){
a = num;
this.str = str;
}
public void printValues(){
System.out.println((count++)+":"+"a="+a+",str="+str);
}
}
}
控制台输出结果为:1:true false2:true true
3:a=10,str=456
4:a=10,str=456
5:a=20,str=987
6:a=10,str=ddd -->从这里开始不明白了,求大佬帮忙分析分析
7:a=50,str=ddd
8:a=20,str=987
9:a=20,str=987 -------->迷,搞不懂
10:a=50,str=ddd ------->迷,搞不懂
[此贴子已经被作者于2018-5-19 12:01编辑过]