SCJP 1.6版考題 037
出自 陳富國維基館
21. abstract class C1{ 22. public C1(){System.out.print(1);} 23. } 24. class C2 extends C1{ 25. public C2(){System.out.print(2);} 26. } 27. class C3 extends C2{ 28. public C3(){System.out.print(3);} 29. } 30. public class Ctest{ 31. public static void main(String[] a){new C3();} 32. } What is the result? A. 3 B. 23 C. 32 D. 123 E. 321 F. Compilation fails. G. An exception is thrown at runtime.
解答
Ans: D
解說:
當一個建構子中若沒有對本身建構子 (this)或父類別建構子(super)的呼叫,建構子會有一個隱含的super(),即對父類別建構子的呼叫, 因此,在建立C3物件時會呼叫C3的建構子,C3建構子會先叫用C2的建構子…
|