作者king08 (糊涂蛋)
站内java
标题Re: [问题] 关於建构子与继承
时间Mon Sep 11 23:54:55 2006
※ 引述《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