"SCJP 1.6版考題 102" 修訂間的差異
出自 陳富國維基館
								
												
				|   (新頁面:  Given:  10. interface Foo{int bar();}  11. public class Sprite{  12.   public int fubar(Foo foo){return foo.bar();}  13.   public void testFoo(){  14.     fubar(  15.       //insert c...) | 
| (無差異) | 
於 2013年3月30日 (六) 05:40 的最新修訂
Given:
10. interface Foo{int bar();}
11. public class Sprite{
12.   public int fubar(Foo foo){return foo.bar();}
13.   public void testFoo(){
14.     fubar(
15.       //insert code here
16.     );
17.   }
18. }
Which code, inserted at line 15, allows the class Sprite to compile?
  A. Foo{public int bar(){return 1;}}
  B. new Foo{public int bar(){return 1;}}
  C. new Foo(){public int bar(){return 1;}}
  D. new class Foo{public int bar(){return 1;}}
解答
Ans: C
解說: 14行呼叫fubar,參數要帶入一個Foo的物件參考,因此使用new Foo(){…}形式,建立一個Foo物件。
| 
 | ||||||||||||||||||||
