A method 'public static void sort(int[] arr)' sorts the array in place. After calling 'sort(data)', the original array 'data' is changed. Which design issue does this demonstrate?
Changing the original array can lead to unexpected behavior; returning a new array is a common practice.
Why this answer
Option C is correct because the method modifies the original array passed as an argument, which is a side effect. In Java, arrays are objects, and when passed to a method, the reference is passed by value, allowing the method to modify the array's contents. To avoid side effects and maintain immutability, the method should return a new sorted array instead of modifying the original.
Exam trap
The trap here is that candidates often confuse pass-by-value for objects with pass-by-reference, thinking that Java passes objects by reference, which would make modification expected, but the real issue is that the method's side effect violates the principle of least surprise and should be avoided by returning a new array.
How to eliminate wrong answers
Option A is wrong because using a wrapper class for the array does not prevent modification; the wrapper would still hold a reference to the same array, and the method could modify its contents. Option B is wrong because declaring the method as void does not indicate or prevent modification; it merely means the method does not return a value, but it can still modify the array in place. Option D is wrong because Java always uses pass-by-value for method arguments; for objects (including arrays), the reference is passed by value, so the method can modify the object's state, and this is not a design issue but a fundamental language behavior.