|
 
- UID
- 321006
- 帖子
- 73
- 精华
- 0
- 名声
- 722 分贝
- 探客币
- 160 元
- 人品
- 0 %
- 阅读权限
- 80
|
1#
发表于 2008-6-19 21:25
| 只看该作者
[讨论] SCJP考试试题解析十七
SCJP考试试题解析十七
我的QQ号:2535279
www.javaedu.com.cn
Consider the following class:
1. class Test(int i) {
2. void test(int i) {
3. System.out.println(“I am an int.”);
4. }
5. void test(String s) {
6. System.out.println(“I am a string.”);
7. }
8.
9. public static void main(String args[]) {
10. Test t=new Test();
11. char ch=“y”;
12. t.test(ch);
13. }
14. }
Which of the statements below is true?(Choose one.)
A. Line 5 will not compile, because void methods cannot be overridden.
B. Line 12 will not compile, because there is no version of test() that rakes a char argument.
C. The code will compile but will throw an exception at line 12.
D. The code will compile and produce the following output: I am an int.
E. The code will compile and produce the following output: I am a String.
解答:D
点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给void test(int i)方法。 |
|