passing by reference in Java doubts

后端 未结 5 1782
借酒劲吻你
借酒劲吻你 2021-01-26 05:07

So I was reading this post and response no. 2. In that example, after calling that method, does the Dog value at address 42, name\'s changes to Max?

Dog myDog;

         


        
5条回答
  •  无人及你
    2021-01-26 05:21

    Does the Dog value at address 42, name's changes to Max?

    Yes. The name changes

    Dog myDog = new Dog("Rover");
    foo(myDog);
    
    public void foo(Dog someDog) {
        someDog.setName("Max");     // AAA
        someDog = new Dog("Fifi");  // BBB
        someDog.setName("Rowlf");   // CCC
    }
    

提交回复
热议问题