Why do object assignments refer to memory locations when primitive types don't? [duplicate]
This question already has an answer here: Is Java “pass-by-reference” or “pass-by-value”? 84 answers I have a bit of an odd question regarding how primitive types work in Java. When using Objects when you assign an ObjectA to be ObjectB be like such Rectangle ObjectB = new Rectangle(); ObjectA = ObjectB; Any calls to ObjectA refer now to ObjectB's memory location. However when using integers or other primitive types this is not the case. For example int x = 3; int y = x; int x = 5; return y; y will return 3, the value of x when y was initialized. The question I have is why does assignment for