I have a question. I have the next sample of code :
class Test{
static void change(String s){
s = "newString";
}
public static void main(String args[]){
String s = "String";
change(s);
System.out.print(s);
}
}
I see that the result is "String". Now i have the following code :
class A{
int a;
static void change(A a){
a.a = 10;
}
public static void main(String[] args){
A a = new A();
a.a = 5;
change(a);
System.out.print(a.a);
}
}
This ends up with the value 10. I cannot understand why? Aren't they both references? Why isn't the first code output : "newString"?