注册 登录
TechRepubil.com.cn探客网
最具实践价值的IT应用分享平台
返回列表 回复 发帖

[讨论] 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)方法。
正在学习中!!!!!!!!!
问道—回合制网游极品,在繁忙的工作之余要不要体验一下?很好玩!点此查看:  问道推广人   问道推广人   问道
返回列表