0

Why can a calling function see the modified value of an array after it's passed to a called method? Since an array is an object, I'd assume it behaves the same as an object, but it doesn't. Can anyone explains why?

public class test {
  public static void funk(int bird, int[] tiger) { 
    tiger[0] = tiger[0] * 2; 
    bird = tiger[0] + 5;
  } 
  public static void main(String[] args) {
    int bird = 10;
    int[] tiger = {7};
    Test.funk(bird, tiger);

    //bird: 10 --> Not changed
    System.out.println("bird:"+bird);           
    //tiger: [14] --> Changed 
    System.out.println("tiger:"+Arrays.toString(tiger));
  }
}
LED Fantom
  • 1,229
  • 1
  • 12
  • 32

0 Answers0