197k views
5 votes
Identify the correct statement.

a. an array is passed to a method by passing the array's values
b. a method cannot modify the elements of an array argument
c. an array is passed to a method by passing a reference to the array
d. an array is converted to another data type and passed to a method

User Shalin
by
8.0k points

1 Answer

5 votes

Final answer:

An array is passed to a method by passing a reference to the array, allowing modifications to be made to the original array.

Step-by-step explanation:

The correct statement is:

c. an array is passed to a method by passing a reference to the array.

When passing an array to a method in Java, we pass a reference to the array, rather than the array's values. This means that any modifications made to the array inside the method will affect the original array. For example:

// Method that modifies array

void modifyArray(int[] arr) {

arr[0] = 7; // Modifies original array

}

// Creating and passing an array to the method

int[] array = {1, 2, 3};

modifyArray(array);

// The array will now be {7, 2, 3}

User Cola
by
9.2k points