单项选择题
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?()
A. null
B. finally
C. null finally
D. Compilation fails.
E. finally exception
相关考题
-
单项选择题
static void test() throws Error { if (true) throw new AssertionError(); System.out.print(”test “); } public static void main(String[] args) { try { test(); } catch (Exception ex) { System.out.print(”exception “); } System.out.print(”elld “); } What is the result?()
A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main. -
单项选择题
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?()
A. test
B. Exception
C. Compilation fails.
D. NullPointerException -
单项选择题
1.publicclassa{ 2.publicvoidmethod1(){ 3.try{ 4.Bb=newb(); 5.b.method2(); 6.//morecodehere 7.}catch(TestExceptionte){ 8.thrownewRuntimeException(te); 9.} 10.} 11.} 1.publicclassb{ 2.publicvoidmethod2()throwsTestException{ 3.//morecodehere 4.} 5.} 1.publicclassTestExceptionextendsException{ 2.} Given: 31.publicvoidmethod(){ 32.Aa=newa(); 33.a.method1(); 34.} WhichistrueifaTestExceptionisthrownonline3ofclassb?()
A. Line 33 must be called within a try block.
B. The exception thrown by method1 in class a is not required to be caught.
C. The method declared on line 31 must be declared to throw a RuntimeException.
D. On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.
