"SCJP 1.6版考題 074" 修訂間的差異
出自 陳富國維基館
(新頁面: Which two classes correctly implement both the java.lang.Runnable and the java.lang.Cloneable interfaces? (Choose two.) A. public class Session implements Runnable, clon...) |
(無差異)
|
於 2013年3月30日 (六) 06:36 的修訂
Which two classes correctly implement both the java.lang.Runnable and the java.lang.Cloneable interfaces? (Choose two.) A. public class Session implements Runnable, cloneable { public void run(); public Object clone(); } B. public class Session extends Runnable, Cloneable { public void run(){/* do something */} public Object clone(){/* make a copy */} }
C. public class Session implements Runnable, Cloneable { public void run(){/* do something */} public Object clone() {/* make a copy */} } D. public abstract class Session implements Runnable, Cloneable { public void run(){/* do something */} public Object clone(){/* make a copy */} }
E. public class Session implements Runnable, implements Cloneable { public void run(){/* do something */} public Object clone() {/* make a copy */} }
解答
Ans: C D
解說:
此題問那二個類別正確地實作Runnable與Cloneable介面 A錯是因為既然實作了介面,就必須把介面中的抽象方法實作寫出來,run和clone方法依然是抽象的。 B錯是類跑不能用extends去繼承介面 E錯是寫法不對(要如C和D寫法)
|