Finally
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第1题:
public class foo { public static void main (string[]args) try {return;} finally {system.out.printIn(“Finally”);} } What is the result?()
第2题:
static void test() { try { String x=null; System.out.print(x.toString() +“ “); } finally { System.out.print(“finally “); } } public static void main(String[] args) { try { test(); } catch (Exception ex) { System.out.print(”exception “); } } 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 Foo { public static void main(String[] args) { try { return; } finally { System.out.println( “Finally” ); } } } What is the result?()
第5题:
public class TestOne { public static void main (String[] args) throws Exception { Thread.sleep(3000); System.out.println(”sleep”); } } What is the result?()
第6题:
Given 1. public class Foo { 2. public static void main (String [] args) } 3. try { return;} 4. finally { Syste.out.printIn (“Finally”);} 5. } 6. } What is the result( )?
第7题:
Tested
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第8题:
Finally
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第9题:
The program runs and prints nothing.
The program runs and prints “Finally”
The code compiles, but an exception is thrown at runtime.
The code will not compile because the catch block is missing.
第10题:
finally
exception finished
finally exception finished
Compilation fails.
第11题:
NULL
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第12题:
The program runs and prints nothing.
The program runs and prints “Finally”.
The code comiles. But an exception is thrown at runtime.
The code will not compile because the catch block is missing.
第13题:
public class Test { public static void main(String[] args) { String str = NULL; System.out.println(str); } } 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题:
public class Test { public static void main(String args[]) { class Foo { public int i = 3; } Object o = (Object)new Foo(); Foo foo = (Foo)o; System.out.println(“i = “ + foo.i); } } What is the result?()
第16题:
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?()
第17题:
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?()
第18题:
null
finally
null finally
Compilation fails.
finally exception
第19题:
i = 3
Compilation fails.
A ClassCastException is thrown at line 6.
A ClassCastException is thrown at line 7.
第20题:
The program runs and prints nothing.
The program runs and prints “Finally”
The code compiles, but an exception is thrown at runtime.
The code will not compile because the catch block is missing.
第21题:
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”.
第22题:
true
null
false
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第23题:
0.0
Compilation fails.
A ParseException is thrown by the parse method at runtime.
A NumberFormatException is thrown by the parse method at runtime.
第24题:
Class A
Compilation fails.
An exception is thrown at line 2.
An exception is thrown at line 6.
The code executes with no output.