单项选择题
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. -
多项选择题
1. public class A { 2. public void method1() { 3. B b=new B(); 4. b.method2(); 5. // more code here 6. } 7. } 1. public class B { 2. public void method2() { 3.C c=new C(); 4. c.method3(); 5. // more code here 6. } 7. } 1. public class C { 2. public void method3() { 3. // more code here 4. } 5. } Given: 25. try { 26. A a=new A(); 27. a.method1(); 28. } catch (Exception e) { 29. System.out.print(”an error occurred”); 30. } Which two are true if a NullPointerException is thrown on line 3 of class C?()
A. The application will crash.
B. The code on line 29 will be executed.
C. The code on line 5 of class A will execute.
D. The code on line 5 of class B will execute.
E. The exception will be propagated back to line 27.
