I have to get something straight. Please tell me if I'm correct:
String a;
String b;
a = b means that b takes the value of a?
And
b = a means that a takes the value of b?
I'm awkwardly confused about this & I'd appreciate an explanation.
Generally, a = b
means "a
becomes b
". However, this is only part of the story when we talk about Object
s (as opposed to primitives). After the assignment both variables or fields reference the same object. When object allows changes (which String
does not) any changes you perform on a
take an effect on b
as well, and vice versa.
This can be illustrated with a simple diagram:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With