SCJP(OCPJP) 考古題解析 第13題

Given:

public class Barn {
    public static void main(String[] args) {
        new Barn.go("hi", 1);
        new Barn.go("hi", "world", 2);
    }
    public void go(String... y, int x) {
        System.out.print(y[y.length - 1] + " ");
    }
}

What is the result?

A. hi hi
B. hi world
C. world world
D. Compilation fails.
E. An exception is thrown at runtime.


答案:


解析:

Varargs(多參數)方法只能擺在參數列的最後

0 意見:

張貼留言