java认证考试试卷_java认证考试试题及答案

java认证考试试卷_java认证考试试题及答案java认证考试试题及答案故答案为C。12.Whatistheresultafterthefollowingcodeexecutes?1shorts=0x00FD;2byteb=(byte)s;3System.out.println(b);Select1correctanswer:A.Compiletimeerrorinline1B.Comp…

大家好,又见面了,我是你们的朋友全栈君。

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

答案:A

14. Here is the ActionEvent family tree:

java.lang.Object

|— java.util.EventObject

|— java.awt.AWTEvent

|—- java.awt.event.ActionEvent

Suppose we have the following code to count events and

save the most recent event:

int evtCt = 0 ;

AWTEvent lastE ;

public void saveEvent( AWTEvent evt )

{

lastE = evt ;

evtCt++ ;

}

Which of the following calls of saveEvent would run

without causing an exception?

Select all possible answers:

A. call with an AWTEvent object reference

B. call with an ActionEvent object reference

C. call with an EventObject object reference

D. call with null value

答案:ABD

15. Suppose we have two classes defined as follows:

class ApBase extends Object implements Runnable

class ApDerived extends ApBase implements Observer

Given two variables created as follows:

ApBase aBase = new ApBase() ;

ApDerived aDer = new ApDerived();

Which of the following Java code fragments will

compile and execute without error?

Select 1 correct answer:

A. Object obj = aBase ; Runnable rn = obj ;

B. Object obj = aBase ; Runnable rn = (Runnable) obj ;

C. Object obj = aBase ; Observer ob = (Observer)aBase ;

D. Object obj = aDer ; Observer ob2 = obj ;

答案:B?

16. The following lists the complete contents

of the file named Derived.java:

1. public class Base extends Object {

2. String objType ;

3. public Base(){ objType = “I am a Base type” ;

4. }

5. }

6.

7. public class Derived extends Base {

8. public Derived() { objType = “I am a Derived type”;

9. }

10. public static void main(String args[] ){

11. Derived D = new Derived();

12. }

13. }

What will happen when this file is compiled?

Select 1 correct answer:

A. Two class files, Base.class and Derived.class will be created

B. The compiler will object to line 1

C. The compiler will object to line 7

解析:

答案:B

17. The following method is designed to convert an input string

to a floating point number, while detecting a bad format.

Assume that factor is correctly defined elsewhere:

public boolean strCvt( String s ){

try {

factor = Double.valueOf( s ).doubleValue();

return true ;

} catch(NumberFormatException e){

System.out.println(“Bad number ” + s );

factor = Double.NaN ;

}finally { System.out.println(“Finally”);

}

return false ; }

Which of the following descriptions of the results of various

inputs to the method are correct? Select all possible answers:

A. Input = “0.234”

Result:factor = 0.234, “Finally” is printed, true is returned.

B. Input = “0.234”

Result:factor = 0.234, “Finally” is printed, false is returned.

C. Input = null

Result:factor = NaN, “Finally” is printed, false is returned.

D. Input = null

Result:factor unchanged,”Finally” is printed,

NullPointerException is thrown.

解析:finally无论在什么情况下都会执行。

对于double.valueof,当输入为null(注意,不是字符串null,字符串null仍然会导致NumberFormatException)时,会导致NullPointerException

答案:A D

18. Here is the hierarchy of Exceptions related to

array index errors:

Exception

+– RuntimeException

+– IndexOutOfBoundsException

+– ArrayIndexOutOfBoundsException

+– StringIndexOutOfBoundsException

Suppose you had a method X which could throw both

array index and string index exceptions. Assuming

that X does not have any try – catch statements,

which of the following statements are correct?

A. The declaration for X must include

“throws ArrayIndexOutOfBoundsException,

StringIndexOutOfBoundsException”.

B. If a method calling X catches IndexOutOfBoundsException, both

array and string index exceptions will be caught.

C. If the declaration for X includes “throwsIndexOutOfBoundsException”,

any calling method must use a try – catch block.

D. The declaration for X does not have to mention exceptions.

解析:RuntimeException是运行时异常,属于不可查异常,程序无需声明,也无需处理。

答案:BD

19. Given the following listing of the Widget class:

1 class Widget extends Thingee{

2 static private int widgetCount = 0 ;

3 public String wName ;

4 int wNumber ;

5

6 static synchronized int addWidget(){ widgetCount++ ;

7 wName = “I am Widget # ” + widgetCount ;

8 return widgetCount ;

9 }

10 public Widget(){

11 wNumber = addWidget();

12 }

13 }

What happens when we try to compile the class and use

multiple Widget objects in a program?

Select 1 correct answer:

A. The class compiles and each Widget will get a unique wNumber

and wName reflecting the order in which the Widgets were created.

B. The compiler objects to line 7

C. A runtime error occurs in the addWidget method

答案:B 原因:静态方法操作的必须是静态变量

20. Given the following class definition:

public class DerivedDemo extends Demo

{

int M, N, L ;

public DerivedDemo( int x, int y )

{

M = x ; N = y ;

}

public DerivedDemo( int x )

{

super( x );

}

}

Which of the following constructor signatures MUST exist

in the Demo class for DerivedDemo to compile correctly?

Select 2 correct answers:

A. public Demo( int a, int b )

B. public Demo( int c )

C. public Demo( )

答案:B C

相关文章推荐:

【java认证考试试题及答案】相关文章:

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/156482.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 微信公众平台接口调试工具

    微信公众平台接口调试工具微信公众平台为公众号开发者提供了网页版的接口调试工具,开发者可以直接在网页中调用对应的接口,比如获取access_token接口,创建菜单接口,发送消息接口等等。 先看一下界面,访问:http://mp.weixin.qq.com/debug/可以看到如下界面: 一、接口类型:因为微信公众号接口比较多,所以这里进行了分类,包括:基础支持、向用户发送消息、用户管理、自定义…

    2022年6月23日
    23
  • LoadRunner11在Win10 下的激活成功教程解决办法(整合)

    LoadRunner11在Win10 下的激活成功教程解决办法(整合)1.loadrunner在win10中因管理员安装完成之后,进行激活成功教程会出现如下问题这是因为win10系统下,该程序没有用管理员方式运行2.然后我们用管理员方式运行,出现如下错误3.解决管理员组织的问题解决步骤:1》.进入”控制面板“–”用户账户“–”用户账户“,选择”更改用户账户控制设置“,选择最后一项,点击”确定“按钮,如下图:2》.按【win+R】快捷…

    2022年7月22日
    13
  • centos7系统更新命令_centos 更新

    centos7系统更新命令_centos 更新1.查看网络IP ifconfig2.下载命令 wget+网址3.安装 yum-y install + 目标4.删除文件 sudo rm 文件所在目录/目标强制删除文件 rm -f删除目录 rm -rf5.复制一个文件到另一个文件夹sudo cp /文件夹/文件 /另一个文件夹6.对一些文件进行读写sudo vim 文件名7….

    2022年8月18日
    23
  • pythondecode函数的用法_如何使用python中的decode函数?[通俗易懂]

    pythondecode函数的用法_如何使用python中的decode函数?[通俗易懂]我们在使用Python的过程中,是通过编码实现的。编码格式是可以设定的,如果我们想要输入时编码格式时字符串编码,这时可以使用python中的decode函数。decode函数可以以encoding指定的编码格式解码字符串,并默认编码为字符串编码。1、decode函数以encoding指定的编码格式解码字符串,默认编码为字符串编码。2、decode()方法的语法str.decode(enco…

    2022年7月17日
    15
  • ubuntu 18.04 ros melodic_ubuntu查看软件版本

    ubuntu 18.04 ros melodic_ubuntu查看软件版本1.ROS版本选择ROS是一个用于编写机器人软件的灵活框架,它集成了大量的工具、库、协议,提供了类似操作系统所提供的功能,包括硬件抽象描述、底层驱动程序管理、公用功能的执行、程序间的消息传递、程序发行包管理,可以极大简化繁杂多样的机器人平台下的复杂任务创建与稳定行为控制。ROS和Ubuntu版本安装对应关系ROS版本Ubuntu版本indigo14.04kinetic16.04melodic18.04ROS的安装方法主要有两种:软件源安装和源码编译安

    2022年9月10日
    0
  • 微信公众号推广_微信公众号名字

    微信公众号推广_微信公众号名字微信5.0发布2013年8月5日,伴随着微信5.0iPhone版的发布,公众平台也进行了重要的更新,主要包括:1)运营主体为组织,可选择成为服务号或者订阅号;2)服务号可以申请自定义菜单;3)使用QQ登录的公众号,可以升级为邮箱登录;4)使用邮箱登录的公众号,可以修改登录邮箱;5)编辑图文消息可选填作者;6)群发消息可以同步到腾讯微博。其中,大家议论最多的当属前两

    2022年9月1日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号