0
null
Compilation fails.
A NullPointerException is thrown at runtime.
An ArrayIndexOutOfBoundsException is thrown at runtime.
第1题:
public class Test { public static void main(String[] args) { String str = NULL; System.out.println(str); } } What is the result?()
第2题:
public class Test { public int aMethod() { static int i = 0; i++; return i; } public static void main (String args[]) { Test test = new Test(); test.aMethod(); int j = test.aMethod(); System.out.println(j); } } What is the result?()
第3题:
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?()
第4题:
public class Test { private static int[] x; public static void main(String[] args) { System.out.println(x[0]); } } What is the result?()
第5题:
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?()
第6题:
f[0] = 0
f[0] = 0.0
Compilation fails.
An exception is thrown at runtime.
第7题:
true
false
Compilation fails.
An exception is thrown at runtime.
第8题:
baz =
baz = null
baz = blue
Compilation fails.
An exception is thrown at runtime.
第9题:
TestA
TestB
Compilation fails.
An exception is thrown at runtime.
第10题:
int Long
Short Long
Compilation fails.
An exception is thrown at runtime.
第11题:
NULL
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第12题:
short LONG
SHORT LONG
Compilation fails.
An exception is thrown at runtime.
第13题:
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?()
第14题:
public static void main(String[] args) { try { args=null; args[0] = “test”; System.out.println(args[0]); } catch (Exception ex) { System.out.println(”Exception”); } catch (NullPointerException npe) { System.out.println(”NullPointerException”); } } What is the result?()
第15题:
public class Test { public static void main(String[] args) { int x = 0; assert (x > 0) ? “assertion failed” : “assertion passed”; System.out.println(“Finished”); } } What is the result?()
第16题:
public class Wow { public static void go(short n) {System.out.println(”short”); } public static void go(Short n) {System.out.println(”SHORT”);} public static void go(Long n) {System.out.println(” LONG”); } public static void main(String [] args) { Short y= 6; int z=7; go(y); go(z); } } What is the result?()
第17题:
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?()
第18题:
0
null
Compilation fails.
A NullPointerException is thrown at runtime.
An ArrayIndexOutOfBoundsException is thrown at runtime.
第19题:
test
Exception
Compilation fails.
NullPointerException
第20题:
0
1
2
Compilation fails.
第21题:
x = 0
x = 42
Compilation fails because of an error in line 2 of class Test2.
Compilation fails because of an error in line 3 of class Test1.
Compilation fails because of an error in line 4 of class Test2.
第22题:
finished
Compilation fails.
An AssertionError is thrown and finished is output.
An AssertionError is thrown with the message “assertion failed”.
An AssertionError is thrown with the message “assertion passed”.
第23题:
0
3
Compilation fails.
An exception is thrown at runtime.
第24题:
finished
Compilation fails.
An AssertionError is thrown.
An AssertionError is thrown and finished is output.