java认证考试试卷 您所在的位置:网站首页 java认证工程师 java认证考试试卷

java认证考试试卷

2024-07-11 15:18| 来源: 网络整理| 查看: 265

java认证考试试题及答案

故答案为C。

12. What is the result after the following code executes?

1 short s = 0x00FD;

2 byte b = (byte)s;

3 System.out.println(b);

Select 1 correct answer:

A. Compile time error in line 1

B. Compile time error in line 2

C. 0

D. -3

E. -2

解析:考察对强制类型转换的理解,java中,short类型为16位,占据两个字节,byte类型为八位。第二行,对s进行了强制类型转换,而这实际上是一个收缩基本转换,从带符号整数到整型T的收索转换只是简单地丢弃除n个最低阶位以外的其它所有位,这可能导致数目或者符号的变化。

Java中所有的整数类型都具有符号位,故需要考虑二进制表示

b=0xFD=1111 1101,是一个补码。

将最高位为1的补码转换为原码的步骤为(最高位为0的补码和原码相同)先将补码全部取反,然后+1

b取反后得到0000 0010,加1 : 0000 0011,即3,考虑到这是一个附负数,最后的结果为-3

答案:D

13. Given the following method in an application:

1. public String setFileType( String fname ){

2. int p = fname.indexOf( '.' );

3. if( p > 0 ) fname = fname.substring( 0,p );

4. fname += ".TXT";

5. return fname;

6. }

and given that another part of the class has the following code:

7. String TheFile = "Program.java";

8. File F = new File( setFileType( TheFile ) );

9. System.out.println( "Created " + TheFile );

what will be printed by the statement in line 9?

Select 1 correct answer:

A. Created Program.java

B. Created Program.txt

C. Created Program.java.txt



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有