public class Blip{ protected int blipvert(int x){return 0;} } class Vert extends Blip{ //insert code here }
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;}
答案:ACEFG
解析:
X B. private int blipvert(int x){return 0;} - 繼承來的方法存取只能更開放:public>protected>(default)>private
X D. protected long blipvert(int x){return 0;} - Overriding不允許回傳不同型態
1 意見:
繼承來的方法存取只能更開放, 那為何 C 可以?
答案C 也是private
張貼留言