abc
null
abcdef
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第1题:
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?()
第2题:
public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( “Finally” ); } } } What is the result?()
第3题:
System.out.println(Math.sqrt(-4D)); What is the result?()
第4题:
String a = null; a.concat(“abc”); a.concat(“def”); System.out.println(a); What is the result?()
第5题:
class Base { Base() { System.out.print(“Base”); } } public class Alpha extends Base { public static void main( String[] args ) { new Alpha(); new Base(); } } What is the result?()
第6题:
Value: 3
Value: 8
Value: 13
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第7题:
Base
BaseBase
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第8题:
peep
bark
meow
Compilation fails.
An exception is thrown at runtime.
第9题:
Finally
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第10题:
true
null
false
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第11题:
0
1
4
Compilation fails.
An exception is thrown at runtime.
第12题:
Hello
Hello World
Compilation fails.
Hello World 5
The code runs with no output.
An exception is thrown at runtime.
第13题:
public class Drink implements Comparable { public String name; public int compareTo(Object o) { return 0; } } and: Drink one = new Drink(); Drink two = new Drink(); one.name= “Coffee”; two.name= “Tea”; TreeSet set = new TreeSet(); set.add(one); set.add(two); A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?()
第14题:
11. String test = “This is a test”; 12. String[] tokens = test.split(”/s”); 13. System.out.println(tokens.length); What is the result?()
第15题:
interface Beta {} class Alpha implements Beta { String testIt() { return “Tested”; } } public class Main1 { static Beta getIt() { return new Alpha(); } public static void main( String[] args ) { Beta b = getIt(); System.out.println( b.testIt() ); } } What is the result?()
第16题:
public class Foo { public int a; public Foo() { a = 3; } public void addFive() { a += 5; } } and: public class Bar extends Foo { public int a; public Bar() { a = 8; } public void addFive() { this.a +=5; } } invoked with: Foo foo = new Bar(); foo.addFive(); System.out.println(”Value: “+ foo.a); What is the result?()
第17题:
Tested
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第18题:
Tea
Coffee
Coffee Tea
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第19题:
baz =
baz = null
baz = blue
Compilation fails.
An exception is thrown at runtime.
第20题:
null
zero
some
Compilation fails.
An exception is thrown at runtime.
第21题:
–2
NaN
Infinity
Compilation fails.
An exception is thrown at runtime.
第22题:
7
49
343
Compilation fails.
An exception is thrown at runtime.
第23题:
NULL
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.