Compilation fails.
Compilation succeeds with errors.
Compilation succeeds with warnings.
Compilation succeeds without warnings or errors.
第1题:
class A { public A() { System.out.println(“hello from a”); } } class B extends A { public B () { System.out.println(“hello from b”); super(); } } public class Test { public static void main(String args[]) { A a = new B(); } } What is the result when main is executed?()
第2题:
public class Test { public static void main(String[] args) { String str = NULL; System.out.println(str); } } What is the result?()
第3题:
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?()
第4题:
public class Test{ public static void main( String[] argv ){ // insert statement here } } Which statement, inserted at line 3, produces the following output?() Exception in thread “main” java.lang.AssertionError: true at Test.main(Test.java:3)
第5题:
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?()
第6题:
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?()
第7题:
0
null
Compilation fails.
A NullPointerException is thrown at runtime.
An ArrayIndexOutOfBoundsException is thrown at runtime.
第8题:
assert true;
assert false;
assert false : true;
assert false == true;
assert false: false;
第9题:
Compilation fails.
hello from a
hello from b
hello from b hello from a
hello from a hello from b
第10题:
NULL
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第11题:
Compilation succeeds and 4 is printed.
Compilation succeeds and 43 is printed.
An error on line 9 causes compilation to fail.
An error on line 14 causes compilation to fail.
Compilation succeeds but an exception is thrown at line 9.
第12题:
finished
Compilation fails.
An AssertionError is thrown.
An AssertionError is thrown and finished is output.
第13题:
public class Alpha{ public static void main( string[] args ){ if ( args.length == 2 ) { if ( args.[0].equalsIgnoreCase(“-b”) ) System.out.println( new Boolean( args[1] )); } } } And the code is invoked by using the command: java Alpha –b TRUE What is the result?()
第14题:
public class Test { public static void aMethod() throws Exception { try { throw new Exception(); } finally { System.out.println(“finally”); } } public static void main(String args[]) { try { aMethod(); } catch (Exception e) { System.out.println(“exception”); } System.out.println(“finished”); } } What is the result?()
第15题:
11. public class Test { 12. public void foo() { 13. assert false; 14. assert false; 15. } 16. public void bar(){ 17. while(true){ 18. assert false; 19. } 20. assert false; 21. } 22. } What causes compilation to fail?()
第16题:
public class Test { public static void replaceJ(string text) { text.replace (‘j’, ‘l’); } public static void main(String args[]) { string text = new String (“java”) replaceJ(text); system.out.printIn(text); } } What is the result?()
第17题:
public class Test { private static int[] x; public static void main(String[] args) { System.out.println(x[0]); } } What is the result?()
第18题:
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?()
第19题:
true
false
Compilation fails.
An exception is thrown at runtime.
第20题:
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”.
第21题:
true
null
false
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第22题:
Line 13
Line 14
Line 18
Line 20
第23题:
The program prints “lava”
The program prints “java”
An error at line 7 causes compilation to fail.
Compilation succeeds but the program throws an exception.