Given the code fragment?
public class Test {
public static void main(String[] args) {
Test t = new Test();
int[] arr = new int[10];
arr = t.subArray(arr, 0, 2);
}
// insert code here
}
Which method can be inserted at line // insert code here to enable the code to compile?
A.
public int[] subArray(int[] src, int start, int end) {
return src;
}
B.
public int subArray(int src, int start, int end) {
return src;
}
C.
public int[] subArray(int src, int start, int end) {
return src;
}
D.
public int subArray(int[] src, int start, int end) {
return src;
}
題解
程式第 6 行使用到 t 變數所參考到的 Test 物件的 subArray 方法,但是現有的程式並未定義與實作出 subArray 方法。這裡並不需要考慮 subArray 方法的執行結果是否正確,題目只要求編譯成功而已。
在第 6 行 subArray 方法傳入的三個引數分別是整數陣列、整數和整數,而回傳型態是整數陣列,因此選項 A 是正確的。
