Leave a Reply 5

Your email address will not be published. Required fields are marked *


Boldoo

Boldoo

B

pojo

pojo

doChange(arr[0],arr[1],arr[2]);==> I think it cannot compile

Eugene

Eugene

This question is wrong. The correct answer is “Compilation fails”

xxx

xxx

Compilation fails

Roger

Roger

public class Test3 {
public static void doChange(int[] arr) {
for(int pos = 0; pos < arr.length; pos++) {
arr[pos] = arr[pos] + 1;
}
}
public static void main(String[] args) {
int arr[] = {10, 20, 30};
doChange(arr);
for(int x : arr)
System.out.println(x);
doChange(arr[0], arr[1], arr[2]); // does not compile
for(int x : arr)
System.out.println(x);
}
it does not compile, if changed so that it compiles the answer is D