OCP Java17 SE Developers 复习题05

======================答案=========================

======================答案=========================

A, E.  Instance and static variables can be marked final, making option A correct. Effectively final means a local variable is not marked final but whose value does not change after it is set, making option B incorrect. Option C is incorrect, as final refers only to the reference to an object, not its contents. Option D is incorrect, as var and final can be used together. Finally, option E is correct: once a primitive is marked final, it cannot be modified.

======================答案=========================

======================答案=========================

B, C.  The keyword void is a return type. Only the access modifier or optional specifiers are allowed before the return type. Option C is correct, creating a method with private access. Option B is also correct, creating a method with package access and the optional specifier final. Since package access does not use a modifier, we get to jump right to final. Option A is incorrect because package access omits the access modifier rather than specifying default. Option D is incorrect because Java is case sensitive. It would have been correct if public were the choice. Option E is incorrect because the method already has a void return type. Option F is incorrect because labels are not allowed for methods.

======================答案=========================

======================答案=========================

A, D.  Options A and D are correct because the optional specifiers are allowed in any order. Options B and C are incorrect because they each have two return types. Options E and F are incorrect because the return type is before the optional specifier and access modifier, respectively.

======================答案=========================

======================答案=========================

A, B, C, E.  The value 6 can be implicitly promoted to any of the primitive types, making options A, C, and E correct. It can also be autoboxed to Integer, making option B correct. It cannot be both promoted and autoboxed, making options D and F incorrect.

======================答案=========================

======================答案=========================

A, C, D.  Options A and C are correct because a void method is optionally allowed to have a return statement as long as it doesn't try to return a value. Option B does not compile because null requires a reference object as the return type. Since int is primitive, it is not a reference object. Option D is correct because it returns an int value. Option E does not compile because it tries to return a double when the return type is int. Since a double cannot be assigned to an int, it cannot be returned as one either. Option F does not compile because no value is actually returned.

======================答案=========================

======================答案=========================

A, B, F.  Options A and B are correct because the single varargs parameter is the last parameter declared. Option F is correct because it doesn't use any varargs parameters. Option C is incorrect because the varargs parameter is not last. Option D is incorrect because two varargs parameters are not allowed in the same method. Option E is incorrect because the  for a varargs must be after the type, not before it.

======================答案=========================

======================答案=========================

D, F.  Option D passes the initial parameter plus two more to turn into a varargs array of size 2. Option F passes the initial parameter plus an array of size 2. Option A does not compile because it does not pass the initial parameter. Option E does not compile because it does not declare an array properly. It should be new boolean[] {true, true}. Option B creates a varargs array of size 0, and option C creates a varargs array of size 1.

======================答案=========================

======================答案=========================

D.  Option D is correct. A common practice is to set all fields to be private and all methods to be public. Option A is incorrect because protected access allows everything that package access allows and additionally allows subclasses access. Option B is incorrect because the class is public. This means that other classes can see the class. However, they cannot call any of the methods or read any of the fields. It is essentially a useless class. Option C is incorrect because package access applies to the whole package. Option E is incorrect because Java has no such wildcard access capability.

======================答案=========================

======================答案=========================

B, C, D, F.  The two classes are in different packages, which means private access and package access will not compile. This causes compiler errors on lines 5, 6, and 7, making options B, C, and D correct answers. Additionally, protected access will not compile since School does not inherit from Classroom. This causes the compiler error on line 9, making option F a correct answer as well.

======================答案=========================

======================答案=========================

B.  Rope runs line 3, setting LENGTH to 5, and then immediately after that runs the static initializer, which sets it to 10. Line 5 in the Chimp class calls the static method normally and prints swing and a space. Line 6 also calls the static method. Java allows calling a static method through an instance variable, although it is not recommended. Line 7 uses the static import on line 2 to reference LENGTH. For these reasons, option B is correct.

======================答案=========================

======================答案=========================

B, E.  Line 10 does not compile because static methods are not allowed to call instance methods. Even though we are calling play() as if it were an instance method and an instance exists, Java knows play() is really a static method and treats it as such. Since this is the only line that does not compile, option B is correct. If line 10 is removed, the code prints swing-swing, making option E correct. It does not throw a NullPointerException on line 17 because play() is a static method. Java looks at the type of the reference for rope2 and translates the call to Rope.play().

======================答案=========================

======================答案=========================

B.  The test for effectively final is if the final modifier can be added to the local variable and the code still compiles. The monkey variable declared on line 11 is not effectively final because it is modified on line 13. The giraffe and name variables declared on lines 13 and 14, respectively, are effectively final and not modified after they are set. The name variable declared on line 17 is not effectively final since it is modified on line 22. Finally, the food variable on line 18 is not effectively final since it is modified on line 20. Since there are two effectively final variables, option B is correct.

======================答案=========================

======================答案=========================

D.  There are two details to notice in this code. First, note that RopeSwing has an instance initializer and not a static initializer. Since RopeSwing is never constructed, the instance initializer does not run. The other detail is that length is static. Changes from any object update this common static variable. The code prints 8, making option D correct.

======================答案=========================

======================答案=========================

E.  If a variable is static final, it must be set exactly once, and it must be in the declaration line or in a static initialization block. Line 4 doesn't compile because bench is not set in either of these locations. Line 15 doesn't compile because final variables are not allowed to be set after that point. Line 11 doesn't compile because name is set twice: once in the declaration and again in the static block. Line 12 doesn't compile because rightRope is set twice as well. Both are in static initialization blocks. Since four lines do not compile, option E is correct.

======================答案=========================

======================答案=========================

B.  The two valid ways to do this are import static java.util.Collections.*; and import static java.util.Collections.sort;. Option A is incorrect because you can do a static import only on static members. Classes such as Collections require a regular import. Option C is nonsense as method parameters have no business in an import. Options D, E, and F try to trick you into reversing the syntax of import static.

======================答案=========================

======================答案=========================

E.  The argument on line 17 is a short. It can be promoted to an int, so print() on line 5 is invoked. The argument on line 18 is a boolean. It can be autoboxed to a Boolean, so print() on line 11 is invoked. The argument on line 19 is a double. It can be autoboxed to a Double, so print() on line 11 is invoked. Therefore, the output is int-Object-Object-, and the correct answer is option E.

======================答案=========================

======================答案=========================

B.  Since Java is pass-by-value and the variable on line 8 never gets reassigned, it stays as 9. In the method squarex starts as 9. The y value becomes 81, and then x gets set to –1. Line 9 does set result to 81. However, we are printing out value, and that is still 9, making option B correct.

======================答案=========================

======================答案=========================

B, D, E.  Since Java is pass-by-value, assigning a new object to a does not change the caller. Calling append() does affect the caller because both the method parameter and the caller have a reference to the same object. Finally, returning a value does pass the reference to the caller for assignment to s3. For these reasons, options B, D, and E are correct.

======================答案=========================

======================答案=========================

B, C, E.  The variable value1 is a final instance variable. It can be set only once: in the variable declaration, an instance initializer, or a constructor. Option A does not compile because the final variable was already set in the declaration. The variable value2 is a static variable. Both instance and static initializers are able to access static variables, making options B and E correct. The variable value3 is an instance variable. Options D and F do not compile because a static initializer does not have access to instance variables.

======================答案=========================

======================答案=========================

A, E.  The 100 parameter is an int and so calls the matching int method, making option A correct. When this method is removed, Java looks for the next most specific constructor. Java prefers autoboxing to varargs, so it chooses the Integer constructor. The 100L parameter is a long. Since it can't be converted into a smaller type, it is autoboxed into a Long, and then the method for Object is called, making option E correct.

======================答案=========================

======================答案=========================

A, E.  The 100 parameter is an int and so calls the matching int method, making option A correct. When this method is removed, Java looks for the next most specific constructor. Java prefers autoboxing to varargs, so it chooses the Integer constructor. The 100L parameter is a long. Since it can't be converted into a smaller type, it is autoboxed into a Long, and then the method for Object is called, making option E correct.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/157795.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ideal远程Debug部署在服务器上的服务详解

ideal远程Debug部署在服务器上的服务详解 一 简介二 ideal配置步骤第一步:点击Edit Configurations选项添加远程连接第二步:配置Remote JVM debug参数第三步:服务的启动参数中添加第二步生成的命令并重新启动服务第四步:ideal启动…

Linux 部署 GitLab idea 连接

概述 GitLab 是一个开源的代码管理平台,使用 Git 作为版本控制工具,提供了 Web 界面和多种功能,如 wiki、issue 跟踪、CI/CD 等。 GitLab 可以自托管或使用 SaaS 服务,支持多种操作系统和执行器。 GitLab 可以帮助软件开发团队…

Windows中将tomcat以服务的形式安装,然后在服务进行启动管理

Windows中将tomcat以服务的形式安装,然后在服务进行启动管理 第一步: 在已经安装好的tomcat的bin目录下: 输入cmd,进入命令窗口 安装服务: 输入如下命令,最后是你的服务名,避免中文和特殊字符 service.…

呼叫中心系统信息发送功能的应用

通常情况下功能比较齐全的呼叫中心系统都会有短信功能,那么短信功能在呼叫中心职场中有哪些应用呢? 呼叫中心系统中短信功能主要分为三部分:短信发送、待发送短信、短信发件箱,先来简单了解一下这三个功能在工作中如何使用。 短信…

[Vue]之Jwt的入门和Jwt工具类的使用及Jwt集成spa项目

一,jwt入门 1.1 是什么? JWT,全称为 JSON Web Token,是一种用于在网络应用之间传递信息的标准方法。它是基于 JSON 格式定义的一种简洁且自包含的方式,可以安全地在用户和服务之间传输声明信息 1.2 为什么要使用 ①简…

vue面试题-应用层

MVC与MVVM MVCMVVM 双向数据绑定 vue2 双向绑定原理 v-model原理 vue3 双向绑定原理 示例 对比 vue2响应式原理和Vue3响应式原理 data为什么是函数?v-if 与 v-show MVC与MVVM MVC和MVVM是两种流行的设计模式,它们都是用于构建动态应用程序的框架。 MVC MVC&#…

Jetson Orin NX 开发指南(7): EGO-Swarm 的编译与运行

一、前言 EGO-Planner 浙江大学 FAST-LAB 实验室的开源轨迹规划算法是,受到 IEEE Spectrum 等知名科技媒体的报道,其理论技术较为前沿,是一种不依赖于ESDF,基于B样条的规划算法,并且规划成功率、算法消耗时间、代价数…

openGauss学习笔记-98 openGauss 数据库管理-管理数据库安全-客户端接入认证之配置客户端接入认证

文章目录 openGauss学习笔记-98 openGauss 数据库管理-管理数据库安全-客户端接入认证之配置客户端接入认证98.1 背景信息98.2 操作步骤98.3 异常处理98.4 示例 openGauss学习笔记-98 openGauss 数据库管理-管理数据库安全-客户端接入认证之配置客户端接入认证 98.1 背景信息 …

Gpt-4多模态功能强势上线,景联文科技多模态数据采集标注服务等您来体验!

就在上个月,OpenAI 宣布对ChatGPT 进行重大更新,该模型不仅能够通过文字输入进行识别和分析,还能够通过语音、图像甚至视频等多种模态的输入来获取、识别、分析和输出信息。这一重要技术突破,将促进多模态自然语言处理的发展&…

Jmeter脚本参数化和正则匹配

我们在做接口测试过程中,往往会遇到以下几种情况 每次发送请求,都需要更改参数值为未使用的参数值,比如手机号注册、动态时间等 上一个接口的请求体参数用于下一个接口的请求体参数 上一个接口的响应体参数用于下一个接口的请求体参数&#…

private key ssh连接服务器

这里用到的软件是PuTTY。 https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html 保存本地rsa文件后,打开软件PuTTYgen,点击Load导入文件,输入Key passphrase即密码,保存至本地。 随后在PuTTY配置ssh的用户名 来Cred…

基于Linux安装Hive

Hive安装包下载地址 Index of /dist/hive 上传解压 [rootmaster opt]# cd /usr/local/ [rootmaster local]# tar -zxvf /opt/apache-hive-3.1.2-bin.tar.gz重命名及更改权限 mv apache-hive-3.1.2-bin hivechown -R hadoop:hadoop hive配置环境变量 #编辑配置 vi /etc/pro…

MySQL——源码安装教程

MySQL 一、MySQL的安装1、RPM2、二进制3、源码 二、源码安装方式三、安装过程1、上传源码包2、解压当前文件并安装更新依赖3、对MySQL进行编译安装 四、其他步骤 一、MySQL的安装 首先这里我来介绍下MySQL的几种安装方式: 一共三种,RPM安装包、二进制包…

数据库第三次作业

1、使用源码安装MySQL8.0.x。 进入MySQL官方网站中下载适合你操作系统的源代码包MySQLhttps://www.mysql.com/复制下载链接,用wget命令安装。 [rootlocalhost ~]# wget https://repo.mysql.com//mysql80-community-release-el9-4.noarch.rpm [rootlocalhost ~]# r…

详解cv2.addWeighted函数【使用 OpenCV 添加(混合)两个图像-Python版本】

文章目录 简介函数原型代码示例参考资料 简介 有的时候我们需要将两张图片在alpha通道进行混合,比如深度学习数据集增强方式MixUp。OpenCV的addWeighted提供了相关操作,瓷片博客将详细介绍这个函数,并给出代码示例。🚀&#x1f6…

MTK6877/MT6877天玑900安卓5G核心板_安卓开发板主板定制开发

2021年5月13日,MediaTek 宣布发布旗下的天玑900系列芯片,又名MT6877。天玑900基于6nm先进工艺制造,搭载硬件级4K HDR视频录制引擎,支持1.08亿像素摄像头、5G双全网通和Wi-Fi 6连接、旗舰级存储规格和120Hz的FHD超高清分辨率显示&a…

华为汪涛:5.5G时代UBB目标网,跃升数字生产力

[阿联酋,迪拜,2023年10月12日] 在2023全球超宽带高峰论坛上,华为常务董事、ICT基础设施业务管理委员会主任汪涛发表了“5.5G时代UBB目标网,跃升数字生产力”的主题发言,分享了超宽带产业的最新思考与实践,探…

Spring实战 | Spring AOP核心功能分析之葵花宝典

国庆中秋特辑系列文章: 国庆中秋特辑(八)Spring Boot项目如何使用JPA 国庆中秋特辑(七)Java软件工程师常见20道编程面试题 国庆中秋特辑(六)大学生常见30道宝藏编程面试题 国庆中秋特辑&…

uniapp 一次性上传多条视频 u-upload accept=“video“ uni.chooseMedia uni.uploadFile

方式 一 部分安卓机 只能一条一条传视频 文档地址 uview 2.0 Upload 上传组件 html <view class"formupload"><u-upload accept"video":fileList"fileList3" afterRead"afterRead" delete"deletePic" name"…

[Swift]同一个工程管理多个Target

1.准备 先创建一个测试工程“ADemo”&#xff0c;右键其Target选择Duplicate&#xff0c;再复制一个Target为“ADemo2”。 再选择TARGETS下方的“”&#xff0c;添加一个APP到项目中&#xff0c;这个命名为“BDemo”。 2、管理多个Target 可以对三个target分别导入不同的框…