Re: [問題] constructor invoke another constructor
※ 引述《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
09/22 13:06, 1F
推
09/22 17:33, , 2F
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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):