看板 java 關於我們 聯絡資訊
※ 引述《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