object a = object b; what happens to object a?

后端 未结 6 1732
轻奢々
轻奢々 2021-01-17 15:22

One of my professor has given us a few practice questions for an exam, and one of the questions is something like the below (psuedocode):

a.setColor(blue);
b         


        
6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-17 15:26

    The important thing to realize is, after the line a = b, you don't have two objects anymore. You have two variables, both referring to the same object. So when you change that object's color, both variables reflect it. the line b = a actually doesn't do anything.

提交回复
热议问题