Re: [問題] 關於建構子與繼承

看板java作者 (糊塗蛋)時間19年前 (2006/09/11 23:44), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/4 (看更多)
※ 引述《Taique (阿薩布魯‧湖瀾)》之銘言: : ============================================================ : class B extends A{ : private int x,y; : B(int x, int y){ : this.x=x;this.y=y;} : void printXY(){System.out.print("B: x=" + x + ", y=" + y);} : public static void main(String[] args){ : A t = new B(1,2); : t.printXY();} : } : class A{ : private int x,y; : A(int x, int y){ : this.x=x;this.y=y;} : void printXY(){System.out.print("A: x=" + x + ", y=" + y);} : } : ============================================================= : 上面的程式碼為什麼會產生找不到class A的Constructor的compile error? : 不是應該會有 Default Constructor 嗎? Default constructor 只有在未設定Constructor 時才會自動幫你補上去 你在class A就已經給自定的Constructor,所以就沒Default的Constructor -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.225.206.197
文章代碼(AID): #151OHbtd (java)
文章代碼(AID): #151OHbtd (java)