Pass the method parameter by value problem

Why the output is still "x = 20" ?

Should I use wrapper Integer class since the method

multi() pass the parameter by value, not by reference?

public class ManagerTest

{

public static void main(String[] args)

{int x = 20;

ManagerTest mt = new ManagerTest();

mt.multi(x);

System.out.println("x = " + x);

}

public void multi(int y)

{

y = y*y;

}

}

[447 byte] By [xpproject] at [2007-9-27 21:03:37]
# 1
Primitive data types (int, char, byte, float, long,...) are passed by value.
bbritta at 2007-7-7 2:45:39 > top of Java-index,Archived Forums,Java Programming...
# 2

Here's what I would do:

public class ManagerTest

{

public static void main(String[] args)

{int x = 20;

ManagerTest mt = new ManagerTest();

x = mt.multi(x);

System.out.println("x = " + x);

}

public int multi(int y)

{

return y*y;

}

}

atmguy at 2007-7-7 2:45:39 > top of Java-index,Archived Forums,Java Programming...