When I pass an object to a method via a parameter, is the object passed by value or reference? The question comes from this code:
int a = 2;
cambiar(a);
System.out.println(a);
public static void cambiar(int c) {
c = 10;
}
In the code above I already knew that I was not going to modify a a
in any way unless the method returned an int and saved it. But in the following code what happens?
class otraCualquiera {
Partidas partidas = new Partidas();
Ventana ventana = new Ventana();
Gestor gestor = new Gestor(ventana,partidas);
}
class culquiera {
private Ventana view;
private Partidas play;
public Gestor(Ventana v, Partidas p) {
view = v;
play = p;
}
}
The main question, why can I directly modify the other classes from the class anyone? ( view.setTitle("View sería un jframe")
) and from the first code I showed I can't modify the int
?