1. 问下面这段程序的输出结果？

public class VLA2 implements Comparator<VLA2> {
int dishSize;

public static void main(String[] args) {
VLA2[] va = { new VLA2(40), new VLA2(200), new VLA2(60) };

Arrays.sort(va, va[0]);
int index = Arrays.binarySearch(va, new VLA2(40), va[0]);
System.out.print(index + " ");
index = Arrays.binarySearch(va, new VLA2(80), va[0]);
System.out.print(index);
}

public int compare(VLA2 a, VLA2 b) {
return b.dishSize - a.dishSize;
}

VLA2(int d) {
dishSize = d;
}
}

A. 0 -2
B. 0 -3
C. 2 -1
D. 2 -2
E. Compilation fails.
F. An exception is thrown at runtime.

sort(T[] a, Comparator<? super T> c)
Sorts the specified array of objects according to the order induced by the specified comparator.

binarySearch(T[] a, T key, Comparator<? super T> c)
Searches the specified array for the specified object using the binary search algorithm.

function Binary_Search(L,a,b,x); begin if a&gt;b then return(-1) else begin m:=(a+b) div 2; if x=L[m] then return(m) else if x&gt;L[m] then return(Binary_Search(L,m+1,b,x)); else return(Binary_Search(L,a,m-1,x)); end; end;

T(n)=2+T(n/2),T(1)=1

public static <T> int binarySearch(T[] a, int fromIndex, int toIndex,
T key, Comparator<? super T> c) {
rangeCheck(a.length, fromIndex, toIndex);
return binarySearch0(a, fromIndex, toIndex, key, c);
}

// Like public version, but without range checks.
private static <T> int binarySearch0(T[] a, int fromIndex, int toIndex,
T key, Comparator<? super T> c) {
if (c == null) {
return binarySearch0(a, fromIndex, toIndex, key);
}
int low = fromIndex;
int high = toIndex - 1;

while (low <= high) {
int mid = (low + high) >&gt;&gt; 1;
T midVal = a[mid];
int cmp = c.compare(midVal, key);

if (cmp < 0)
low = mid + 1;
else if (cmp > 0)
high = mid - 1;
else
return mid; // key found
}
}

2. 问下面这段程序的输出结果？

public class WeatherTest {
static Weather w;

public static void main(String[] args) {
System.out.print(w.RAINY.count + " " + w.Sunny.count + " ");
}
}

enum Weather {
RAINY,
Sunny;
int count = 0;

Weather() {
System.out.print("c ");
count++;
}
}

A. c 1 c 1
B. c 1 c 2
C. c c 1 1
D. c c 1 2
E. c c 2 2
F. Compilation fails.
G. An exception is thrown at runtime.

3. 问下面这段程序的输出结果？

public class Gazillion {

public static void main(String[] args) throws Exception {
String s = "123.456xyz";
NumberFormat nf = NumberFormat.getInstance();
System.out.println(nf.parse(s));
nf.setMaximumFractionDigits(2);
System.out.println(nf.format(s));
}
}

A. Compilation fails.
B. The output will contain "123.45 "
C. The output will contain "123.456"
D. The output will contain "123.456xyz"
E. An exception will be thrown at runtime.

4. 给出下面这段程序：

2. public class Internet {
3. private int y = 8;
4. public static void main(String[] args) {
5. new Internet().go();
6. }
7. void go() {
8. int x = 7;
9. TCPIP ip = new TCPIP();
10. class TCPIP {
11. void doit() { System.out.println(y + x); }
12. }
13. ip.doit();
14. }
15. }

A. Compilation succeeds.
B. Compilation fails due to an error on line 3.
C. Compilation fails due to an error on line 8.
D. Compilation fails due to an error on line 9.
E. Compilation fails due to an error on line 10.
F. Compilation fails due to accessing x on line 11.
G. Compilation fails due to accessing y on line 11.

5. 给出下面这段程序：

4. public static void main(String[] args) {
5. try {
6. if(args.length == 0) throw new Exception();
7. }
8. catch (Exception e) {
9. System.out.print("done ");
10. doStuff(); // assume this method compiles
11. }
12. finally {
13. System.out.println("finally ");
14. }
15. }

A. "done "
B. "finally "
C. "done finally "
D. Compilation fails.
E. No output is produced.

6. 给出下面这段程序：

public class Two {
public static void main(String[] args) {
int y = 0;
assert y == 0;
if (args.length &gt; 0) new One();
}
}

class One {
int x = 0;
{
assert x == 1;
}
}

A. java Two
B. java Two x
C. java -ea Two
D. java -ea Two x
E. java -ea:One Two
F. java -ea:One Two x
G. java -ea:Two Two x

7. 给出下面这段程序：

public class BeSafe {

}

class SafeDeposit {
private static SafeDeposit singleton;

public static SafeDeposit getInstance(int code) {
if (singleton == null) singleton = new SafeDeposit(code);
return singleton;
}

private int code;

private SafeDeposit(int c) {
code = c;
}

int getCode() {
return code;
}
}

A. Compilation fails.
B. Class BeSafe can create many instances of SafeDeposit.
C. Class BeSafe CANNOT create any instances of SafeDeposit.
D. Class BeSafe can create only one instance of SafeDeposit.
E. Class BeSafe can create instances of SafeDeposit without using the getInstance() method.
F. Once class BeSafe has created an instance of SafeDeposit, it cannot change the value of the instance’s "code" variable.