问题描述
- 一道选择题:这一小段代码允许各种数据库的操作,下面四个选项哪个正确
-
public final class MyClass {private Connection connection; public Example(Connection c){ this.connection = c; } public interface ConnectionWorker{ void doSomething(Connection conn); } public void work(ConnectionWorker worker){ worker.doSomething(connection); }
}
(A) Example can be subclassed in order to specialize the implementation of MyClass.work(ConnectionWorker)
(B) Specialization is achieved through implementation of a ConnectionWorker
(C) The call to worker.doSomething must be synchronized on worker
(D) worker.doSomething must launch a worker thread passing conn and then wait with Thread join
解决方案
A是错的,因为这是final class,CD在代码中没有提到。看上去应该选B。通过实现ConnectionWorker接口并且传给work方法实现对doSomething的Specialization。
时间: 2024-11-16 05:42:46