|
class Base
{
public int i;
public Base (int a)
{
i = a;
}
}
public class StringTest {
public static void changeStr (String str) {
str = "welcome";
}
public static void changeBase (Base b)
{
b.i = 6;
}
public static void main (String [] args) {
String str = "1234";
Base base = new Base (3);
changeBase (base);
System.out.println (base.i);
changeStr (str);
System.out.println (str);
}
}
I thought I understood, but I still did n’t understand
changeBase modified the value of i according to the "object reference" rule,
But changeStr did not follow the "object reference" rule, still "1234"
why? |
|