[問題] SCJP題庫第17題:override或overload ?

看板java作者 (紫苑)時間11年前 (2014/07/23 11:42), 編輯推噓1(104)
留言5則, 5人參與, 最新討論串1/1
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://www.ptt.cc/bbs/java/M.1406086950.A.1F9.html

07/23 11:51, , 1F
因為CFG是overload吧
07/23 11:51, 1F

07/23 12:46, , 2F
你標題不就寫了override or overload ,就overload啊...
07/23 12:46, 2F

07/23 14:21, , 3F
看接收值,ABD是override,CEFG是overload
07/23 14:21, 3F

07/23 15:03, , 4F
給原po keyword: Method Signature
07/23 15:03, 4F

07/25 21:34, , 5F
因為參數long ,所以不是override
07/25 21:34, 5F
文章代碼(AID): #1Jpoyc7v (java)
文章代碼(AID): #1Jpoyc7v (java)