What is the result of the following code? “`java int[] arr = {1, 2, 3}; int[] copy = arr; copy[0] = 99; System.out.println(arr[0]); “`

Java Associate Hard

Java Associate — Hard

What is the result of the following code? “`java int[] arr = {1, 2, 3}; int[] copy = arr; copy[0] = 99; System.out.println(arr[0]); “`

Key points

  • Assigning an array to another variable does not create a new copy of the array
  • Modifying the array through one variable affects all variables pointing to it
  • The value at index 0 of `arr` is changed to 99
  • The code does not result in an ArrayIndexOutOfBoundsException

Ready to go further?

Related questions