SCJP刷题学习笔记(Part six)

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接口:
 
 
 
 
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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值