单项选择题

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.


您可能感兴趣的试卷

你可能感兴趣的试题

1.单项选择题

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.

5.多项选择题

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.

6.单项选择题

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.

7.单项选择题

23.int z=5; 
24. 
25. public void stuff1(int x) { 
26. assert (x> 0); 
27. switch(x) { 
28. case 2: x= 3; 
29. default: assert false; } } 
30. 
31. private void stuff2(int y) { assert (y < 0); } 
32. 
33. private void stuff3() { assert (stuff4O); }
34. 
35. private boolean stuff4() { z = 6; return false; } 
Which is true?() 
 

A. All of the assert statements are used appropriately.
B. Only the assert statement on line 31 is used appropriately.
C. The assert statements on lines 29 and 31 are used appropriately.
D. The assert statements on lines 26 and 29 are used appropriately.
E. The assert statements on lines 29 and 33 are used appropriately.
F. The assert statements on lines 29, 31, and 33 are used appropriately.
G. The assert statements on lines 26, 29, and 31 are used appropriately.

8.单项选择题

public class Test { 
public static void main(String [] args) { 
boolean assert = true; 
if(assert) { 
System.out.println(”assert is true”); 
} 
} 
}
Given: 
javac -source 1.3 Test.java 
What is the result?() 

A. Compilation fails.
B. Compilation succeeds with errors.
C. Compilation succeeds with warnings.
D. Compilation succeeds without warnings or errors.

9.单项选择题

public class AssertStuff { 
public static void main(String [] args) { 
int x= 5; 
int y= 7; 
assert (x> y): “stuff”; 
System.out.println(”passed”); 
} 
} 
And these command line invocations:java AssertStuff java -ea AssertStuff What is the result?()

A. passed stuff
B. stuff passed
C. passed      An AssertionError is thrown with the word “stuff” added to the stack trace.
D. passed      An AssertionError is thrown without the word “stuff” added to the stack trace.
E. passed      An AssertionException is thrown with the word “stuff” added to the stack trace.
F. passed     An AssertionException is thrown without the word “stuff” added to the stack trace.

10.多项选择题

public class test { 
public static void main(String [] a) { 
assert a.length == 1; 
} 
} 
Which two will produce an AssertionError?()

A. java test
B. java -ea test
C. java test file1
D. java -ea test file1
E. java -ea test file1 file2
F. java -ea:test test file1

最新试题

Which statement is true about the set variable on line 12?()

题型:单项选择题

Which three changes should be made to adapt this class to be used safely by multiple threads?()

题型:多项选择题

What is the result?()

题型:单项选择题

Which statement is true?()

题型:单项选择题

Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo() method, which two statements are true?()

题型:多项选择题

Given:  foo and bar are public references available to many other threads, foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait().  From another thread, what provides the most reliable way to ensure that foo will stop executing wait()?()

题型:单项选择题

Given that Triangle implements Runnable, and:Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute?()

题型:多项选择题

A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?()

题型:单项选择题

Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5?()

题型:多项选择题

Which statement is true?()

题型:单项选择题