单项选择题

10. public class ClassA { 
11. public void methodA() { 
12. ClassB classB = new ClassB(); 
13. classB.getValue(); 
14. } 
15. } 
And: 
20. class ClassB { 
21. public ClassC classC; 
22. 
23. public String getValue() { 
24. return classC.getValue(); 
25. } 
26. } 
And: 
30. class ClassC { 
31. public String value; 
32. 
33. public String getValue() { 
34. value = “ClassB”; 
35. return value; 
36. } 
37. } 
Given: 
ClassA a = new ClassA(); 
a.methodA(); 
What is the result?()

A. Compilation fails.
B. ClassC is displayed.
C. The code runs with no output.
D. An exception is thrown at runtime.


您可能感兴趣的试卷

你可能感兴趣的试题

1.单项选择题

11. public void someMethod(Object value) { 
12. // check for null value .... 
20. System.out.println(value.getClass()); 
21. } 
What, inserted at line 12, is the appropriate way to handle a null value?() 

A. assert value == null;
B. assert value !null, “value is null”;
C. if (value == null) { throw new AssertionException(”value is null”);
D. if (value == null) { throw new IllegalArgumentException(”value is null”);

9.单项选择题

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.

10.单项选择题

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.