作者aster30 (紫苑)
看板java
标题[问题] SCJP题库第17题:override或overload ?
时间Wed Jul 23 11:42:27 2014
Given:
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;}
答案B跟D错 ACEFG对
B是因为继承的方法权限只能更开放,故不能用private
但明明C也是private阿,为什麽C对?
D是因为overriding回传型态要跟父类别相同
但明明F/G也改了回传型别,为什麽对?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.227.83.17
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/java/M.1406086950.A.1F9.html
1F:→ Aztecs:因为CFG是overload吧 07/23 11:51
2F:→ pzyc79:你标题不就写了override or overload ,就overload啊... 07/23 12:46
3F:→ Kennyq:看接收值,ABD是override,CEFG是overload 07/23 14:21
4F:→ bleed1979:给原po keyword: Method Signature 07/23 15:03
5F:推 nOhiTmE:因为参数long ,所以不是override 07/25 21:34