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

看板java作者 (阿薩布魯‧湖瀾)時間19年前 (2006/09/11 23:25), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/4 (看更多)
============================================================ 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 嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.225.190.55
文章代碼(AID): #151N_seX (java)
文章代碼(AID): #151N_seX (java)