That's because when you declare
public static void funk(int a, int[] b)
The scope of the variable a is only that method. Then when you change the value, you are changing only the value of that variable in that method.
About the b. Thats a new object reference to the same array created in main, that's why it seems the value does change ( what is changing is the array object underneath )
But try this:
public static void funk(int a, int[] b) {
// create a new reference for b
int[] c = new int[b.length];
c[0] = b[0];
b = c;
// The same.
b[0] = b[0] * 2;
a = b[0] + 5;
}
When you do that you'll the the value of tiger didn't change either ( only the content of the new array c created in funk )
You can simulate the pass by ref using a wrapper. See this post.
Although I haven't got any comments about that
EDIT Just for fun:
I have modified your code to use the wrapper posted above.
It looks pretty strange but looks like it works.
// By ref simulated.
public class Test {
public static void funk(_ a, int[] b) {
b[0] = b[0] * 2;
a.s( b[0] + 5 ) ;
}
public static void main(String[] args) {
_ bird = new _(10);
int[] tiger = {7};
Test.funk( bird , tiger );
System.out.println("bird = " + bird );
System.out.println("tiger = " + tiger[0] );
}
}
Prints
bird = 19
tiger = 14
:-S