abcd
ABCD
dccd
dcba
Compilation fails.
An exception 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题:
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?()
第6题:
42
420
462
42042
Compilation fails.
An exception is thrown at runtime.
第7题:
baz =
baz = null
baz = blue
Compilation fails.
An exception is thrown at runtime.
第8题:
TestA
TestB
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题:
Afoo Afoo
Afoo Bfoo
Bfoo Afoo
Bfoo Bfoo
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题:
1
12
14
123
Compilation fails.
An exception is thrown at runtime.
第13题:
String a = “ABCD”; String b = a.toLowerCase(); b.replace(‘a’, ‘d’); b.replace(‘b’, ‘c’); System.out.println(b); 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题:
11. String test = “This is a test”; 12. String[] tokens = test.split(”/s”); 13. System.out.println(tokens.length); What is the result?()
第17题:
String a = null; a.concat(“abc”); a.concat(“def”); System.out.println(a); What is the result?()
第18题:
abc
null
abcdef
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第19题:
abcd
ABCD
dccd
dcba
Compilation fails.
An exception is thrown at runtime.
第20题:
null
zero
some
Compilation fails.
An exception is thrown at runtime.
第21题:
6
7
10
11
Compilation fails.
An exception is thrown at runtime.
第22题:
0
1
4
Compilation fails.
An exception is thrown at runtime.
第23题:
a b c
1 2 3
a1b2c3
a1 b2 c3
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第24题:
( 难度:中等)给出如下代码片段,运行结果为( ):
String a = “ABCD”;
String b = a.toLowerCase();
b.replace(‘a’, ‘d’);
b.replace(‘b’, ‘c’);
System.out.println;
A.abcd
B.ABCD
C.dccd
D.dcba
答案:A