27.6k views
1 vote
Which of the following lines would correctly fill /* code */ in method getStuff() to return the int array named retArray?

public int[] getStuff(int[] x, int howMany)
{
int[] retArray;

//assume retArray has been properly instantiated

/* code */

}

a. return new int retArray;

b. return x;

c. return new int[0];

d. return new int[];

e. return retArray;

1 Answer

3 votes

Final answer:

The correct line of code to return the int array retArray is option e. return retArray. Option e correctly returns the array without modifying it, ensuring that the original values in retArray are preserved.

Step-by-step explanation:

The correct line of code to return the int array retArray is option e. return retArray;.

The code provided declares the int array retArray but does not assign any values to it. To return retArray, we need to make sure the array has been properly populated with values. Option e correctly returns the array without modifying it, ensuring that the original values in retArray are preserved.

User Taylor Kidd
by
8.5k points