Tuesday, August 24, 2010

Var-args: Buckets.java

Courtesy of Sun Web Learning Center

Given:

 3. public class Buckets {
 4.   public static void main(String[] args) {
 5.     int[] x = {1,2,3};
 6.     int[] y = {4,5,6};
 7.     int[] z = {7,8,9};
 8.     go(x, y, z);
 9.     go(y, z);
10.     go(z);
11.  }
12.  static void go(int[] a, int[]... b) {
13.    System.out.print(a[1] + " ");
14.   }
15. }
What is the result?


A 1 2 3
B 1 4 7
C 2 5 8
D 4 5 6
E Compilation fails.
F An exception is thrown at runtime.

No comments:

Post a Comment