Re: [問題] 繼承和建構子
※ 引述《sioo (加油加油)》之銘言:
: 大家好,我有一個簡單的範例程式
: 當我在子類別B的建構子中要使用到父類別A的method時,
: compiler給我的錯誤訊息是
: cannot find symbol
: symbol: constructor A()
: location:A
: public class B extends A
: {
: public B(int num)
: {
: setNum(num);
: }
因為A class 的建構子中沒有一個沒參數的建構子,所以才會錯,
要把setNum(num);改成super(num);
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.84.0.123
討論串 (同標題文章)