I have a question about changing the values of variables in methods in Java.
This is my code:
public class Test {
public static void funk(int a, int[] b) {
b[0] = b[0] * 2;
a = b[0] + 5;
}
public static void main(String[] args) {
int bird = 10;
int[] tiger = {7};
Test.funk(bird, tiger);
}
}
After the execution of the method Test.funk(bird, tiger)
, the value of bird is not changed - it remains with the value 10
, even though in the funk()
method we have changed the value with a = b[0] + 5;
On the other hand, the value of the element in the array changes, because we have the statement b[0] = b[0] * 2;
I don't understand why one thing changes and the other not? Could someone please explain this for me.