So my question is if an object A has an attribute such as int var; and object B has an attribute int var2 both of the object are instantiated from the same class using the same constructor. For illustrations purposes lets say that var=3 and var2=0 Does assigning object A=B make A.var==0 ? please do motivate your answer for me.
here is more code in case you need more:
public class CarSize{ public CarSize(int x) { this.var=x; } public void call() { doubleVar(this); } private void doubleVar(CarSize cz) { int vara= cz.getVar()*2; CarSize c= new CarSize(vara); cz=c; } public int getVar(){return this.var;} private int var; public static void main(String args[]) { CarSize cz = new CarSize(3); cz.call(); System.out.println(cz.getVar()); } } ANNOUNCEMENT
people please check the code before attemtpting to explain to me what i already know, thanks a lot for your understanding.
A.var= 1andB.var =2and i sayA=BshouldntA.varbe =2 sinceAis now pointing to the same address asBand old values ofAwill get garbage collected?