一道java问题

[复制链接]
查看11 | 回复1 | 2009-3-29 02:30:33 | 显示全部楼层 |阅读模式
Given:
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. }
And 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.
答案:D
哪里出了问题??

回复

使用道具 举报

千问 | 2009-3-29 02:30:33 | 显示全部楼层
应该选A,编译失败吧?因为类B方法调用的类C只声明了没有实例化,不可能调用类C的方法。...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行