单项选择题

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


您可能感兴趣的试卷

你可能感兴趣的试题

4.单项选择题

11. static class A { 
12. void process() throws Exception { throw new Exception(); } 
13. } 
14. static class B extends A { 
15. void process() { System.out.println(”B”); } 
16. } 
17. public static void main(String[] args) { 
18. new B().process(); 
19. } 
What is the result?() 

A. B
B. The code runs with no output.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.

5.单项选择题

11. static classA { 
12. void process() throws Exception { throw new Exception(); } 
13. } 
14. static class B extends A { 
15. void process() { System.out.println(”B “); } 
16. } 
17. public static void main(String[] args) { 
18.A a=new B(); 
19. a.process(); 
20.} 
What is the result?() 

A. B
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.
F. Compilation fails because of an error in line 19.

9.多项选择题

Class TestException 
1. public class TestException extends Exception { 
2. } Class a: 
1. public class a { 
2. 
3. public String sayHello(String name) throws TestException { 
4. 
5. if(name == null) { 
6. throw new TestException(); 
7. } 
8. 
9. return “Hello “+ name; 
10. } 
11. 
12. } 
A programmer wants to use this code in an application:
45. A a=new A(); 
46. System.out.println(a.sayHello(”John”)); 
Which two are true?()

A. Class a will not compile.
B. Line 46 can throw the unchecked exception TestException.
C. Line 45 can throw the unchecked exception TestException.
D. Line 46 will compile if the enclosing method throws a TestException.
E. Line 46 will compile if enclosed in a try block, where TestException is caught.

10.单项选择题

public class SomeException { 
} Class a: 
public class a { 
public void doSomething() { } 
} Class b: 
public class b extends a { 
public void doSomething() throws SomeException { } 
} 
Which is true about the two classes?() 

A. Compilation of both classes will fail.
B. Compilation of both classes will succeed.
C. Compilation of class a will fail. Compilation of class b will succeed.
D. Compilation of class a will fail. Compilation of class a will succeed.