SCJP认证试题(十三)

2023-11-07

1public class A{
2 private int counter = 0;
3
4 public static int getInstanceCount(){
5 return counter;
6 }
7
8 public A(){
9 counter++;
10 }
11}


Given this code from class B:

25 A a1 = new A();
26 A a2 = new A();
27 A a3 = new A();
28 System.out.println(A.getInstanceCount());


What is the result?


A Compilation of class A fails
B Line 28 prints the value 3 to System.out
C Line 28 prints the value 1 to System.out
D A runtime error occurs when line 25 executes
E Compilation fails because of an error in line 28


[color=red]Answer: A[/color]



10 class One{
11 void foo(){}
12 }
13 class Two extends One{
14 //insert method here
15 }



Which three methods,inserted individually at line 14, will correctly complete class Two?(Choose three)


A int foo(){/*mode code here*/}
B void foo(){/*more code here*/}
C public void foo(){/*more code here*/}
D private void foo(){/*more code here*/}
E protected void foo(){/*more code here*/}


[color=red]Answer: B C E[/color]


1	public interface A{
2 String DEFAULT_GREETING = "Hello World";
3 public void method1();
4 }


A programmer wants to create an interface called B that has A as its parent.
Which interface declaration is correct?


A public interface B extends A{}
B public interface B implements A{}
C public interface B instanceOf A{}
D public interface B inheritsFrom A{}


[color=red]Answer : A[/color]


11	public abstract class Shape{
12 int x;
13 int y;
14 public abstract void draw();
15 public void setAnchor(int x, int y){
16 this.x = x;
17 this.y = y;
18 }
19 }


And a class Circle that extends and fully implements the Shape class.
Which is correct?


A Shape s = new Shape();
s.setAnchor(10,10);
s.draw();
B Circle c = new Shape();
c.setAnchor(10,10);
c.draw();
C Shape s = new Circle();
s.setAnchor(10,10);
s.draw();
D Shape s = new Circle();
s->setAnchor(10,10);
s->draw();
E Circle c = new Circle();
c.Shape.setAnchor(10,10);
c.shape.draw();


[color=red]Answer: C
[/color]


Which two code fragments correctly create and initialize a static array of int elements?(Choose two)

A static final int[] a = {100, 200};
B static final int[] a;
static {
a = new int[2];
a[0] = 100;
a[1] = 200;
}
C static final int[] a = new int[2]{100, 200};
D static final int[] a;
static void init(){
a = new int[3];
a[0] = 100;
a[1] = 200;
}


[color=red]Answer : A B[/color]



11 interface DeclareStuff{
12 public static final int EASY = 3;
13 void doStuff(int t);}
14 public class TestDeclare implements DeclareStuff{
15 public static void main(String[] args){
16 int x = 5;
17 new TestDeclare().doStuff(++x);
18 }
19 void doStuff(int s){
20 s += EASY + ++s;
21 System.out.println("S " + s);
22 }
23 }


What is the result?


A s 14
B s 16
C s 10
D Compilation fails
E An exception is thrown at runtime


[color=red]Answer : B[/color]



11 String[] elements = {"for", "tea", "too"};
12 String first = (elements.length > 0)?elements[0]:null;


What is the result?


A Compilation fails
B An exception is thrown at runtime
C The variable first is set to null
D The variable first is set to elements[0].


[color=red]Answer : D
[/color]


11	public class ItemTest{
12 private final int id;
13 public ItemTest(int id){ this.id = id;}
14 public void updateId(int newId){id = newId;}
15
16 public static void main(String[] args){
17 ItemTest fa = new ItemTest(42);
18 fa.updateId(69);
19 System.out.println(fa.id);
20 }
21 }



What is the result?


A Compilation fails
B An exception is thrown at runtime
C The attribute id in the Item object remains unchanged
D The attribute id in the Item object is modified to the new value
E A new Item object is created with the preferred value in the id attribute


[color=red]Answer :A[/color]


SomeException:

1 public class SomeException{
2 }

Class A:

1 public class A{
2 public void doSomething(){}
3 }

Class B:

1 public class B extends A{
2 public void doSomething(){} throws SomeException;
3 }


Which statement is true about the two classes?

A Compilation of both classes will fail
B Compilation of both classes will succeed
C Compilation of class A will fail. Compilation of class B will succeed
D Compilation of class B will fail. Compilation of class A will succeed


[color=red]Answer : D[/color]


A programmer has an algorithm that requires a java.util.List that privides an
efficient implementation of add(0,object), but does not need to support quick
random access.


what supports these requirements?


A java.util.Queue
B java.util.ArrayList
C java.util.LinearList
D java.util.LinkedList


[color=red]Answer: D[/color]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SCJP认证试题(十三) 的相关文章

  • 如何使用可变参数模板声明 std::tuple?

    也许我在这里很天真 但我相信以下代码应该编译 template
  • 运行时动态转换

    有没有一种方法可以在运行时动态转换 如以下伪代码 foreach DataRow row in table Rows foreach DataColumn col in table Columns if row col DBNull Val
  • 从命名管道读取

    我必须实现一个 打印服务器 我有 1 个客户端文件和 1 个服务器文件 include
  • 如何测试抽象类的受保护抽象方法?

    我一直在研究测试名为的抽象类的最佳方法TabsActionFilter 我保证继承自的类TabsActionFilter将有一个名为GetCustomer 在实践中 这种设计似乎效果很好 我遇到的一些问题是弄清楚如何测试OnActionEx
  • Calendar.getActualMaximum(Calendar.WEEK_OF_YEAR) 怪异

    要么我不明白这个方法getActualMaximum int 或字段 WEEK OF YEAR 或者涉及 Sun bug 或全部三个 有人可以向我解释为什么吗 至少在德国语言环境中 以下代码 Locale setDefault Locale
  • 为什么即将推出的 Ranges 库不支持范围内的容器初始化?

    介绍 随着即将推出的 Ranges 库 用两个迭代器表示范围的需要几乎消失了 例如 代替 if std equal begin foo end foo begin bar end bar we have if std ranges equa
  • Fluent NHibernate 一对一映射

    我很难利用 Fluent NHibernate 的 HasOne 映射 基本上 A 类在 B 类中可以有匹配的 只有一条或没有 记录 请帮助定义关系的 AMap 和 BMap 类 谢谢 public class A public virtu
  • WPF 应用程序在每个系统规模上具有相同的大小(与规模无关)

    有没有办法让 WPF 应用程序在每个系统规模上获得相同的大小 当我改变时更改文本 应用程序和其他项目的大小在windows系统设置中125 推荐 to 100 在全高清屏幕中 我的 WPF 应用程序变得太小 为了实现独立的系统缩放应用程序
  • DISM.exe 返回代码?

    我有一个程序调用 dism exe 程序 它在后台运行一些命令 现在 我只检查返回代码 0 或其他任何内容 以显示进程失败或成功 我可以用什么来交叉检查返回代码以获得准确的返回错误 DISM 参考了哪些回报 评论中提供的链接DISMAPI
  • OpenGL 中连续暂停

    void keyPress unsigned char key int x int y int i switch key case f i 3 while i x pos 3 sleep 100 glutPostRedisplay 上面是在
  • while 循环无法访问代码

    当我编译这段代码时 public static void main String args int x 0 while false System out println hello 它显示编译时错误无法访问代码 但是当我将这段代码修改为 p
  • 如何检查单元格是否为空 (Excel\VisualC#)

    我的目标是逐行检查Sheet1为了发现有多少行 所以我放了一个 do while 一旦到达空白单元格就应该停止 Example 第 1 行数据第2行数据第3行数据第4行数据第5行数据 第 6 行数据第7行数据 在本例中 我只需要前 5 行
  • 修改排列算法以防止重复打印输出的策略

    我一直在审查实践算法 目前正在研究一种我非常喜欢的排列算法 void permute char set int begin int end int range end begin if range 1 cout lt lt set lt l
  • 执行按钮单击时使 wpf UI 响应

    在我的 wpf c 应用程序中 当用户按下按钮时会执行一个很长的过程 当按下按钮直到执行完整的代码时 窗口将冻结 用户无法在窗口中执行任何其他任务 如何使按钮单击代码作为后台进程 以便窗口响应用户 我尝试过以下方法 但没有成功 privat
  • 封闭实例的匿名类

    我正在阅读 Joshua Bloch 的 Effective Java 第二版 目前我在第 22 项 它描述了内部类和嵌套类 但我无法理解他这句话的意思 匿名类具有封闭实例当且仅当它们发生时 在非静态上下文中 有人能给我一个代码示例并解释它
  • lwjgl 3 , glUniformMatrix4 导致 jre 崩溃

    我正在使用 lwjgl 3 并学习现代 opengl 3 我想将统一矩阵发送到顶点着色器 以便我可以应用转换 我尝试过 但程序因此错误而崩溃 A fatal error has been detected by the Java Runti
  • 升压参数库

    最近我发现参数 http www boost org doc libs 1 50 0 libs parameter doc html index htmlBoost 中的库 老实说 我不明白为什么这是 Boost 的一部分 当需要向函数传递
  • 虚拟继承 - 跳过构造函数

    我有以下课程 class Socket Socket Socket SOCKET s class Connection public virtual Socket Connection IP ip 这两个类包含一些纯虚函数和一些非虚函数以及
  • 检测 Windows 重新启动是否是由于 Windows 更新造成的

    我的电脑上的一些应用程序一直在检测 Windows 更新是否重新启动 这是可以观察到的 因为它们会在 Windows 更新自动重启后重新启动 这非常有帮助 因为这些应用程序会重新加载更改 甚至unsaved更改或恢复选项卡 如果是浏览器 执
  • 如何将谓词作为参数传递#

    如何将谓词传递到方法中 但在没有传递谓词的情况下仍使其工作 我想也许是这样的 但似乎并不正确 private bool NoFilter return true private List

随机推荐

  • html 发件人怎么设置,a标签创建mailto链接发送电子邮箱用法详解

    在html5中 利用标签的mailto可以创建发送邮件到一个或多个电子邮箱的超链接功能 其用法详解如下 标签mailto最常见用法 这个用法是最常见的用法 在大多数情况下 我们都会使用这个方式发送电子邮件 1 发送一个邮箱 书写格式 联系博
  • STM32 开机一直进IDLE空闲中断的解决思路

    串口IDLE空闲中断 常用于串口DMA IDLE中断接收不定长数据 一开始玩DMA 调试程序在一直进入IDLE中断时候 可能是没有软件清零 STM32中文参考手册这么描述的 IDLE 检测到空闲线路 IDLE line detected 检
  • 热更新_ToLua学习示例 06_LuaCoroutine2

    function CoExample WaitForSeconds 1 作者封装的协程等待一秒 print WaitForSeconds end time UnityEngine Time time WaitForFixedUpdate 等
  • cas单点登录系列1.3:自定义登录页

    cas单点登录系列1 3 自定义登录页 cas提供登录页比较大众 我们根据需求进行自定义 所以本节会介绍登录页的一些内容 比较简单 大家可根据情况进行学习 文章目录 cas单点登录系列1 3 自定义登录页 前言 一 登录页组成 二 登录接口
  • java中使用jxls导出excel,excel单元格换行,多sheet页导出

    一 模板 jxls通过模板中的批注语法来渲染数据 所以写好模板已经成功了一大半 我的模板如下 这里我定义了两个sheet页 第一个sheet页就是汇总的 直接取数据遍历 第二个sheet页就是动态sheet页的模板 注意模板作用域的定义一定
  • Python总复习——简答题篇

    简答题篇 1 简述元祖 列表和字典的区别 2 简述局部变量和全部局变量的区别 3 简述闭包满足的三个条件 4 简述导入模块的方法 1 简述元祖 列表和字典的区别 名称 外形 存储结构 访问方式 是否可变类型 列表 中括号括起来的数据 可以存
  • 软件测试工程师技术发展规划 (2022初稿)

    软件测试工程师技术发展规划 2022 2022年3月18日22 19 04 1 不同Level的技术标准 1 1 级别一 测试工程师TE 1 1 1 主要工作内容 1 2 级别二 测试开发工程师 1 2 1 主要工作内容 1 2 2 工作组
  • Java中static关键字详解

    1 1概述 static是静态修饰符 什么叫静态修饰符呢 大家都知道 在程序中任何变量或者代码都是在编译时由系统自动分配内存来存储的 而所谓静态就是指在编译后所分配的内存会一直存在 直到程序退出内存才会释放这个空间 也就是只要程序在运行 那
  • Azure Blob Storage 基本用法上传/下载(Java)

    文章目录 简单概念 Blob Storage Azure Blob Storage的存储结构 Azure Storage Account Container Blob 操作 Maven依赖 创建Container对象 获取Blob列表 下载
  • 图像识别最好的算法,图片相似度识别算法

    现在人脸识别最有效的算法是什么 最好的人脸识别系统在理想情况下比人类识别的表现要好的多 但是一旦环境情况变糟 系统的表现就差强人意了 而计算机科学家们当然是非常想要开发出一种算法 在各种情况下都能够表现优异 现在 中国香港大学的汤晓鸥教授和
  • Three.js3D可视化介绍,以及本地搭建three.js官网

    一 什么是Three js three js官网 https threejs org Three js是一个基于WebGL的JavaScript 3D图形库 它可以轻松地在浏览器中创建3D场景和动画 同时 它支持外部模型和纹理的导入 让开发
  • Windows Server2012R2 VisualSVN4.2.2-Server在线修改密码搭建

    最近有个3 0 0的svn环境要升级可以web界面自助修改密码的 为了找到这个解决方案 我搜索了很多文章与资料 有不少文章提供的总是各种很隐约 好像它要藏着啥好东西似的 我觉得既然你选择了分享你的成果 那就应该把整个过程整理顺畅 而不是在文
  • python解决数组奇数和偶数位置排序问题

    题目描述 输入一个整数数组 实现一个函数来调整该数组中数字的顺序 使得所有的奇数位于数组的前半部分 所有的偶数位于数组的后半部分 并保证奇数和奇数 偶数和偶数之间的相对位置不变 题目解析 这个题目很简单 只需要判断数组中的元素是奇数还是偶数
  • 生成随机数函数:rand和srand

    头文件为 stdlib h rand 会随机生成一个位于 0 RAND MAX 之间的整数 RAND MAX 是
  • [算法] 深搜整理

    深搜 之前在leetcode上刷题一直都对这个知识点比较模糊 最近 集中写了几道深搜的题目 将自己的思路和题目做了整理写下此篇博客 博客很多题目是网上提供的一些深搜题目 另外一些是leetcode上关于深搜的题目 六角填数 如下图所示六角形
  • 转 C#中的委托和事件 - Part.1

    http www tracefact net tech 009 html C 中的委托和事件 Part 1 2007 9 23 作者 张子阳 分类 C 语言 注意 文中代码在VS2005下通过 由于VS2003 Net Framework
  • jquery mobile实现拨打电话功能

    在做一个便民服务电话 用到移动web中列出的电话 点击需要实现调用通讯录 拨打电话功能 如果需要在移动浏览器中实现拨打电话 发送email 调用sns等功能 jquery mobile提供的接口是一个好办法 采用url链接的方式 实现在Sa
  • mipi-CSI2驱动接口调试 LCD 的CLK时钟频率与显示分辨率及帧率的关系

    锋影 email 174176320 qq com 我们先来看一个公式 Mipiclock width hsync hfp hbp x height vsync vfp vbp x bus width x fps lane num 2 即m
  • 让Unity中的多个模型共用同一个材质球

    如何让Unity中的多个模型共用同一个材质球呢 下面我就来分享一下我之前在做模型的时候所使用的方法和思路 供大家学习 Unity文档中曾明确提到 尽可能的共用Material 这主要是因为渲染引擎一般会按照材质对需要渲染的对象进行排序 同一
  • SCJP认证试题(十三)

    1public class A 2 private int counter 0 3 4 public static int getInstanceCount 5 return counter 6 7 8 public A 9 counter