A developer writes a method that takes an int array and returns the sum of its elements. The method signature is: 'public static int sumArray(int[] arr)'. Which statement correctly calls this method?
Trap 1: int result = sumArray(true);
Passes a boolean, not an array.
Trap 2: int result = sumArray([1,2,3]);
Invalid syntax; use new int[]{...}.
Trap 3: int result = sumArray(5);
Passes an int, not an array.
- A
int result = sumArray(new int[]{1,2,3});
Creates and passes an anonymous int array.
- B
int result = sumArray(true);
Why wrong: Passes a boolean, not an array.
- C
int result = sumArray([1,2,3]);
Why wrong: Invalid syntax; use new int[]{...}.
- D
int result = sumArray(5);
Why wrong: Passes an int, not an array.