2009年2月3日 星期二

第13題 SampleCode

1. public class Barn{
2. public static void main(String[] args){
3. new Barn.go("hi", 1);
4. new Barn.go("hi", "world", 2);
5. }
6. public void go(String... y, int x){
7. System.out.print(y[y.length-1] + " ");
8. }
9. }
What is the result?
A. hi hi
B. hi world
C. world world
D. Compilation fails.
E. An exception is thrown at runtime.
-------------------------------------------------------------------------------
答案:D

public class test13 {
public static void main(String[] args) {
new test13.go("hi",1); new test13.go("hi", "world",2);
}
//The variable argument type String of the method go
//must be the last parameter
public void go( String...y,int x) {
System.out.print(y[y.length - 1] + " ");
}
}

ANS:
D. Compilation fails.
---------------------------------------------------------------------------
error msg
The variable argument type String of the method go must be the last parameter

沒有留言:

張貼留言