6
7
10
11
Compilation fails.
Anexception is thrown at runtime.
第1题:
public static void main(String[] args) { String str = “null‟; if (str == null) { System.out.println(”null”); } else (str.length() == 0) { System.out.println(”zero”); } else { System.out.println(”some”); } } What is the result?()
第2题:
public static void main(String[] args) { for (int i=0;i<= 10;i++){ if( i>6) break; } System.out.println(i); } What is the result?()
第3题:
public class Test { public static void main(String[] args) { String str = NULL; System.out.println(str); } } What is the result?()
第4题:
public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( “Finally” ); } } } What is the result?()
第5题:
public class Test { private static int[] x; public static void main(String[] args) { System.out.println(x[0]); } } What is the result?()
第6题:
public class Test { public static void main(String [] args) { System.out.println(args.length > 4 && args[4].equals(“-d”)); } } If the program is invoked using the command line: java Test One Two Three –d What is the result?()
第7题:
0
null
Compilation fails.
A NullPointerException is thrown at runtime.
An ArrayIndexOutOfBoundsException is thrown at runtime.
第8题:
baz =
baz = null
baz = blue
Compilation fails.
An exception is thrown at runtime.
第9题:
null
zero
some
Compilation fails.
An exception is thrown at runtime.
第10题:
6
7
10
11
Compilation fails.
An exception is thrown at runtime.
第11题:
0.0
Compilation fails.
A ParseException is thrown by the parse method at runtime.
A NumberFormatException is thrown by the parse method at runtime.
第12题:
finished
Compilation fails.
An AssertionError is thrown.
An AssertionError is thrown and finished is output.
第13题:
public class Test { private static float[] f = new float[2]; public static void main(String args[]) { System.out.println(“f[0] = “ + f[0]); } } What is the result?()
第14题:
class TestA { public void start() { System.out.println(”TestA”); } } public class TestB extends TestA { public void start() { System.out.println(”TestB”); } public static void main(String[] args) { ((TestA)new TestB()).start(); } } What is the result?()
第15题:
public class Test { public static void main( String[] args) { String foo = args[1]; String bar = args[2]; String baz = args[3]; System.out.println(“baz = “ + baz); } } And the command line invocation: java Test red green blue What is the result?()
第16题:
public class Yikes { public static void go(Long n) {System.out.println(”Long “);} public static void go(Short n) {System.out.println(”Short “);} public static void go(int n) {System.out.println(”int “);} public static void main(String [] args) { short y= 6; long z= 7; go(y); go(z); } } What is the result?()
第17题:
public class Test { public static void main(String[] args) { int x = 0; assert (x > 0): “assertion failed”; System.out.println(“finished”); } } What is the result?()
第18题:
f[0] = 0
f[0] = 0.0
Compilation fails.
An exception is thrown at runtime.
第19题:
true
false
Compilation fails.
An exception is thrown at runtime.
第20题:
TestA
TestB
Compilation fails.
An exception is thrown at runtime.
第21题:
Finally
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第22题:
NULL
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第23题:
0
3
Compilation fails.
An exception is thrown at runtime.