Re: [問題] constructor invoke another constructor

看板java作者 (嗯....?)時間11年前 (2012/09/22 00:31), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串2/2 (看更多)
※ 引述《NPcomplete (Non-deterministic)》之銘言: : Hello everyone, : "The benefit of having one constructor invoke another overloaded constructor : is to avoid code duplication." : 讀書時看到這句並不了解為什麼 : 想請問有沒有人可以解釋 : 或是直接給我一個例子 : 感謝~~ 這樣子的話有感覺嗎? Case 1: public 綠茶() { 綠茶(正常, 正常); } public 綠茶(甜度, 冰塊) { this.甜度 = 甜度; this.冰塊 = 冰塊; } Case 2: public 綠茶() { this.甜度 = 正常; this.冰塊 = 正常; } public 綠茶(甜度, 冰塊) { this.甜度 = 甜度; this.冰塊 = 冰塊; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.250.54.136

09/22 13:06, , 1F
有感覺 XD
09/22 13:06, 1F

09/22 17:33, , 2F
超有感覺的啊 XDDD
09/22 17:33, 2F

09/22 20:08, , 3F
謝謝
09/22 20:08, 3F

09/30 00:52, , 4F
很好!
09/30 00:52, 4F
文章代碼(AID): #1GN9PFgj (java)
文章代碼(AID): #1GN9PFgj (java)