Re: [問題] 關於建構子與繼承
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 4 篇):