Calling a Void Method with Parameters

AP Computer Science A· difficulty 3/5

public class Helper {
    public static void fill(int[] a) {
        a[0] = 99;
    }
}
// ...
int[] arr = {1, 2, 3};
Helper.fill(arr);
System.out.println(arr[0]);

What is printed?

  • A

    99

    check_circle
  • B

    1

  • C

    0

  • D

    Compile-time error

Explanation

Arrays are reference types; the method modifies the same array object, so arr[0] becomes 99.

Want 10 more like this — adaptive to your weak spots?

Related questions