If I pass a object into a method and I change that object in that method will it keep its changes? I'm not sure if I've worded this right so I'll give an example:
public void methodThatChangesX(ClassWithVariableX var) {
var.x = 5;
}
ExampleClass var = new ExampleClass();
//ExampleClass's x's default is 6
methodThatChangesX(var);
System.out.println("x = " + var.x);
Would var's x be 5 or 6? Is there a reason for this?
Aucun commentaire:
Enregistrer un commentaire