QUESTION 51

Given:

final class Folder { //line n1
//line n2
public void open () {
System.out.print(“Open”);
}
}
public class Test {
public static void main (String [] args) throws Exception {
try (Folder f = new Folder()) {
f.open();
}
}
}

Which two modifications enable the code to print Open Close? (Choose two.)
A. Replace line n1 with:
class Folder implements AutoCloseable {
B. Replace line n1 with:
class Folder extends Closeable {
C. Replace line n1 with:
class Folder extends Exception {
D. At line n2, insert:
final void close () {
System.out.print(“Close”);
}
E. At line n2, insert:
public void close () throws IOException {
System.out.print(“Close”);
}
Correct Answer: AE
Section: (none)
Explanation
Explanation/Reference:
Partthree涉及到的AutoCloseable,Closeable和Flushable接口:
https://blog.csdn.net/weixin_30656145/article/details/98637024
QUESTION 52
You want to create a singleton class by using the Singleton design pattern.
Which two statements enforce the singleton nature of the design? (Choose two.)
A. Make the class static.
B. Make the constructor private.
C. Override equals() and hashCode() methods of the java.lang.Object class.
D. Use a static reference to point to the single instance.
E. Implement the Serializable interface.
Correct Answer: BD
Section: (none)
Explanation
Explanation/Reference:
QUESTION 53

Given the code fragment:

9. Connection conn = DriveManager.getConnection(dbURL, userName, passWord);
10. String query = “SELECT id FROM Employee”;
11. try (Statement stmt = conn.createStatement()) {
12. ResultSet rs = stmt.executeQuery(query);
13. stmt.executeQuery(“SELECT id FROM Customer”);
14. while (rs.next()) {
15. //process the results
16. System.out.println(“Employee ID: “+ rs.getInt(“id”));
17. }
18. } catch (Exception e) {
19. System.out.println (“Error”);
20. }
Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the dbURL, userName, and passWord exists.
The Employee and Customer tables are available and each table has id column with a few records and
the SQL queries are valid.
What is the result of compiling and executing this code fragment?
A. The program prints employee IDs.
B. The program prints customer IDs.
C. The program prints Error.
D. compilation fails on line 13.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 54
Given the code fragment:
List<Integer> codes = Arrays.asList (10, 20);
UnaryOperator<Double> uo = s -> s +10.0;
codes.replaceAll(uo);
codes.forEach(c -> System.out.println(c));

What is the result?
A. 20.0
30.0
B. 10
20
C. A compilation error occurs.
D. A NumberFormatException is thrown at run time.
Correct Answer: C
Section: (none)
Explanation
Syntax error on token "Invalid Character", delete this token
Explanation/Reference:Part one 涉及到的UnaryOperator说明:
https://blog.csdn.net/qq_28410283/article/details/80634319
 
QUESTION 55
Given:
public class Customer {
private String fName;
private String lName;
private static int count;
public Customer (String first, String last) {fName = first; lName = last;
++count;}
static { count = 0; }
public static int getCount() {return count; }
}
public class App {
public static void main (String [] args) {
Customer c1 = new Customer(“Larry”, “Smith”);
Customer c2 = new Customer(“Pedro”, “Gonzales”);
Customer c3 = new Customer(“Penny”, “Jones”);
Customer c4 = new Customer(“Lars”, “Svenson”);
c4 = null;
c3 = c2;
System.out.println (Customer.getCount());
}
}
What is the result?
A. 0
B. 2
C. 3
D. 4
E. 5
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
重载与重写的区别:https://blog.csdn.net/linzhaojie525/article/details/55213010
QUESTION 56
Given:
Item table
• ID, INTEGER: PK
• DESCRIP, VARCHAR(100)
• PRICE, REAL
• QUANTITY< INTEGER

And given the code fragment:
9. try {
10. Connection conn = DriveManager.getConnection(dbURL, username, password);
11. String query = “Select * FROM Item WHERE ID = 110”;
12. Statement stmt = conn.createStatement();
13. ResultSet rs = stmt.executeQuery(query);
14. while(rs.next()) {
15. System.out.println(“ID: “ + rs.getInt(“Id”));
16. System.out.println(“Description: “ + rs.getString(“Descrip”));
17. System.out.println(“Price: “ + rs.getDouble(“Price”));
18. System.out.println(Quantity: “ + rs.getInt(“Quantity”));
19. }
20. } catch (SQLException se) {
21. System.out.println(“Error”);
22. }

Assume that:
The required database driver is configured in the classpath.
The appropriate database is accessible with the dbURL, userName, and passWord exists.
The SQL query is valid.
What is the result?
A. An exception is thrown at runtime.
B. Compilation fails.
C. The code prints Error.
D. The code prints information about Item 110.
Correct Answer: D
Section: (none)
Explanation
Explanation/Reference:
QUESTION 57
Given:
class Worker extends Thread {
CyclicBarrier cb;
public Worker(CyclicBarrier cb) { this.cb = cb; }
public void run () {
try {
cb.await();
System.out.println(“Worker…”);
} catch (Exception ex) { }
}
}
class Master implements Runnable { //line n1
public void run () {
System.out.println(“Master…”);
}
}

and the code fragment:
Master master = new Master();
//line n2
Worker worker = new Worker(cb);
worker.start();

You have been asked to ensure that the run methods of both the Worker and Master classes are
executed.
Which modification meets the requirement?
A. At line n2, insert CyclicBarrier cb = new CyclicBarrier(2, master);
B. Replace line n1 with class Master extends Thread {
C. At line n2, insert CyclicBarrier cb = new CyclicBarrier(1, master);
D. At line n2, insert CyclicBarrier cb = new CyclicBarrier(master);
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
CyclicBarrier(栅栏)使用详解:https://blog.csdn.net/J080624/article/details/85261930
QUESTION 58
Given the code fragment:
String str = “Java is a programming language”;
ToIntFunction<String> indexVal = str: : indexOf; //line n1
int x = indexVal.applyAsInt(“Java”); //line n2
System.out.println(x);

What is the result?
A. 0
B. 1
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
常用lamdba函数式接口​​​​​​​:https://blog.csdn.net/Mr_PH/article/details/82424607
QUESTION 59
Given the code fragment:
List<String> codes = Arrays.asList (“DOC”, “MPEG”, “JPEG”);
codes.forEach (c -> System.out.print(c + “ “));
String fmt = codes.stream()
.filter (s-> s.contains (“PEG”))
.reduce((s, t) -> s + t).get();
System.out.println(“\n” + fmt);

What is the result?
A. DOC MPEG JPEG
MPEGJPEG
B. DOC MPEG MPEGJPEG
MPEGMPEGJPEG
C. MPEGJPEG
MPEGJPEG
D. The order of the output is unpredictable.
Correct Answer: A
Section: (none)
Explanation
Explanation/Reference:
Part two 涉及到的Stream语法:https://blog.csdn.net/SeanTandol/article/details/86630437
QUESTION 60
Given the code fragment:
    List<String> nL = Arrays.asList("Jim", "John", "Jeff");Function<String, String> funVal = s -> "Hello : ".concat(s);nL.stream().map(funVal).peek(System.out::print);

What is the result?
A. Hello : Jim Hello : John Hello : Jeff
B. Jim John Jeff
C. The program prints nothing.
D. A compilation error occurs.
Correct Answer: C
Section: (none)
Explanation
Explanation/Reference:
Part one 涉及到的Function拓展说明:https://blog.csdn.net/justry_deng/article/details/100886475
Part two 涉及到的Stream语法:https://blog.csdn.net/SeanTandol/article/details/86630437

SCJP刷题学习笔记(Part six)相关推荐

  1. SCJP刷题学习笔记(Part four)

    之前发的章节开始慢慢更新运行截图以及知识点. QUESTION 31 Given the code fragment: public static void main (String [] args) ...

  2. SCJP刷题学习笔记(Part one)

    测试Java版本"1.8.0_131" 工具为eclipse QUESTION 1 Given the definition of the Vehicle class: class ...

  3. 手机号正则_一起刷题学习正则表达式

    在我最开始学习正则表达式的时候看到一堆符号简直头晕,所以很长一段时间我都是百度一下某某正则怎么写,比如:匹配所有手机号码的正则,但是有时候工作中碰到的一些问题网上搜不到,这就尴尬了,后面还是逼着自己花 ...

  4. 力扣刷题学习SQL篇——1-8 查询(按日期分组销售产品——利用聚合函数GROUP_CONCAT)

    力扣刷题学习SQL篇--1-8 查询(按日期分组销售产品--利用聚合函数GROUP_CONCAT) 1.题目 2.解法 3.group_concat() 1.题目 题目链接:https://leetc ...

  5. 各大编程语言、软件,电子电路刷题学习网站链接及微信公众号

    20210813 增加一些公众号 一些对程序员有用的网站 https://mp.weixin.qq.com/s/GiEbcBSReaKrVezjGA9_fA 20210715:公众号:拓跋啊秀 资源: ...

  6. 神了,无意中发现一位1500道的2021LeetCode算法刷题pdf笔记

    昨晚逛GitHub,无意中看到一位大佬的算法刷题笔记,感觉发现了宝藏!有些小伙伴可能已经发现了,但咱这里还是忍不住安利一波,怕有些小伙伴没有看到. 关于算法刷题的困惑和疑问也经常听朋友们提及.这份笔记 ...

  7. 无意中发现一位大佬的算法刷题pdf笔记

    昨晚逛GitHub,无意中看到一位大佬(https://github.com/halfrost)的算法刷题笔记,感觉发现了宝藏!有些小伙伴可能已经发现了,但咱这里还是忍不住安利一波,怕有些小伙伴没有看 ...

  8. LeetCode刷题复盘笔记—1373. 二叉搜索子树的最大键值和

    今日主要总结一下,1373. 二叉搜索子树的最大键值和 题目:1373. 二叉搜索子树的最大键值和 Leetcode题目地址 题目描述: 给你一棵以 root 为根的 二叉树 ,请你返回 任意 二叉搜 ...

  9. BZOJ 2038: [2009国家集训队]小Z的袜子(hose)【莫队算法裸题学习笔记】

    2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MB Submit: 9894  Solved: 4561 [Su ...

  10. 刷题学习—算法思想(动态规划下)

    24.买卖股票的最佳时机系列 24.1买卖股票的最佳时机 你只能选择 某一天 买入这只股票,并选择在 未来的某一个不同的日子 卖出该股票.设计一个算法来计算你所能获取的最大利润. 只能一笔交易 cla ...

最新文章

  1. Git中.gitignore忽略文件(maven项目)
  2. 深入理解计算机系统:进程
  3. java scanner_Java Scanner radix()方法与示例
  4. java 反射 接口_Java 怎么通过反射获取并实现这个类里面的接口,并且实现接口中的方法...
  5. 《高质量程序设计指南:C++/C语言》图书信息
  6. QT实现简单的抽奖界面
  7. 详解动态代理及其实现原理
  8. android版本高低有啥好处与不好,WP跟安卓比流畅 但为什么就不好用呢?
  9. 光凭求职技巧如何可以突围?
  10. c语言自学报告格式,C语言程序设计实验报告优秀范文
  11. ffmpeg中h264_mp4toannexb使用说明及注意事项
  12. macbook清理磁盘空间
  13. CoreOS容器云企业实战(3)--Docker技术实践
  14. java ftp 上传下载
  15. 大厂与小厂招人的区别,看完多少有点不敢相信
  16. 2021年危险化学品经营单位安全管理人员考试报名及危险化学品经营单位安全管理人员找解析
  17. 全球暗网监控工具 TOP 10
  18. 管道模型(Pipeline)
  19. PHP、Windows、Linux生成大文件
  20. 搭建LNMP实现分离

热门文章

  1. 和画意思相近的字_画字五行属什么,画字在名字里的含义,画字起名的寓意_卜易居起名字典...
  2. 黑苹果OC引导添加AX200无线网卡驱动
  3. c语言prn文件,C语言prntf和scanf函数.doc
  4. ssm 酒店管理系统
  5. python笔记整理
  6. web前端三大主流框架分析对比
  7. OA项目之我的审批(查询会议签字)
  8. 计算机网络系统juniper
  9. 解决添加打印机print spooler打印服务自动关闭故障
  10. 计算机应用教研室工作计划,高校教研室工作计划