"SCJP 1.6版考題 048" 修訂間的差異
出自 陳富國維基館
(新頁面: 1. public class Venus{ 2. public static void main(String[] args){ 3. int[] x = {1, 2, 3}; 4. int y[] = {4, 5, 6}; 5. new Venus().go(x, y); 6. } 7. void go(int[...) |
(無差異)
|
於 2013年3月30日 (六) 07:29 的最新修訂
1. public class Venus{
2. public static void main(String[] args){
3. int[] x = {1, 2, 3};
4. int y[] = {4, 5, 6};
5. new Venus().go(x, y);
6. }
7. void go(int[]... z){
8. for(int[] a : z)
9. System.out.print(a[0]);
10. }
11.}
What is the result?
A. 1
B. 12
C. 14
D. 123
E. Compilation fails.
F. An exception is thrown at runtime.
解答
Ans: C
解說:
go(x, y); 將二個一維整數陣列代入,使用enhanced for走訪這二個陣列,
第一次走訪{1, 2, 3},a[0] ->1,第二次走訪{4, 5, 6},a[0]-> 4
int[]...的意思是說有0~多個的一維陣列會傳入這個參數。
| ||||||||||||||||||||