注册 登录
编程论坛 JAVA论坛

弱鸡求助,怎么就分析不明白呢?

有多难 发布于 2018-05-19 11:26, 2688 次点击
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编辑过]

9 回复
#2
疯狂的小a2018-05-19 11:40
这个有什么意义,这么长,要怎么帮你看?
#3
有多难2018-05-19 11:54
回复 2楼 疯狂的小a
我也不知道有什么意义,,这就是笔试题。不明白的就是   
    public A testRef(A aRef){
        aRef.printValues();
        aRef.str = "ddd";
        aRef = new A(20,"987");
        aRef.printValues();
        return aRef;
    }这个方法调用完之后再aA.printValues()的时候为什么输出的结果是这个-->6:a=10,str=ddd
#4
疯狂的小a2018-05-19 13:31
那个SB出这么长的笔试题,居然要输出十几次
#5
有多难2018-05-19 15:34
回复 4楼 疯狂的小a
不要吐槽了 要崩了 大佬帮帮忙
#6
疯狂的小a2018-05-19 15:48
我试了一下debug,表示没耐心看下去,不好意思!
#7
有多难2018-05-19 17:06
回复 6楼 疯狂的小a
好吧
#8
有多难2018-05-19 18:59
弄明白了,画了一下内存分析,终于搞清楚问题出在哪儿了,我是真的厉害,啧啧啧
#9
LovelyFellas2018-05-23 10:35
题目, 注释,都没有, 我们怎么看,
#10
有多难2018-06-03 22:13
回复 9楼 LovelyFellas
题目就是分析程序,写出程序执行后控制台的输出结果。要啥注释
1