Hello,
I have a questions about changing the values of variables in methods in Java.
I have the following example class:
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 10, though in the funk() method we have the following statement:
a = b[0] + 5;
On the other hand, the value of the element in the array changes, because we have this statement:
b[0] = b[0] * 2;
However, I don't understand why one thing changes and the other not ?
Thanks a lot.
Regards