SCJP 1.6版考題 017
出自 陳富國維基館
1. public class Blip{
2. protected int blipvert(int x){return 0;}
3. }
4. class Vert extends Blip{
5. //insert code here
6. }
Which five methods, inserted independently at line 5, will compile? (Choose five.)
A. public int blipvert(int x){return 0;}
B. private int blipvert(int x){return 0;}
C. private int blipvert(long x){return 0;}
D. protected long blipvert(int x){return 0;}
E. protected int blipvert(long x){return 0;}
F. protected long blipvert(long x){return 0;}
G. protected long blipvert(int x, int y){return 0;}
解答
Ans: A C E F G
解說:
這是考覆載的觀念, 在子類別中重寫(覆載)父類別的方法(方法名一樣,參數列一樣、回傳值型態一樣), 必須要遵守子類別重寫的方法的存取屬性不能更封閉。 C/E/F/G 沒有問題是因為其參數不一樣,基本上就是不同的方法(overload,同名異式) B錯,是因為開放性變小 D錯是因為回傳值型態不一樣。 (只要參數列一樣,就意謂是一樣的方法。)
| ||||||||||||||||||||