2009年2月6日 星期五

第37題

Given:
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.


------------------------------------------------------------------------------
答案:D
參考:6-5 繼承

目的考建構式的觀念,
31. public static void main(String[] a){new C3();}
>>27. class C3 extends C2{
>>>>24. class C2 extends C1{
>>>>>>21. abstract class C1{
>>>>>>>>22. public C1(){System.out.print(1);}
>>>>>>>>>>25. public C2(){System.out.print(2);}
>>>>>>>>>>>>28. public C3(){System.out.print(3);}

沒有留言:

張貼留言