Topic: java的构造方法

  Print this page

1.java的构造方法 Copy to clipboard
Posted by: dawnlong2000
Posted on: 2005-01-19 17:52

java类一旦指定了带参数的构造方法后,若不保留不带参数的构造方法,子类
将无法生成,因为无论子类构造方法是否带参数,编译都无法通过。这是为什么?
例子:
public class Bean{
public Bean(int a){
}
public void test(){
}
}
子类:
public class SubBean{
public SubBean(int a){
}

public SubBean(){
}
}

2.Re:java的构造方法 [Re: dawnlong2000] Copy to clipboard
Posted by: lover
Posted on: 2005-01-19 20:57

public SubBean(int a) }
super(); //隐形的调用。系统自己调用的。

}

3.Re:java的构造方法 [Re: lover] Copy to clipboard
Posted by: dawnlong2000
Posted on: 2005-01-20 17:10

Sorry,i'm mistaken.
in class SubBean,the following constructor declaration will be OK.
public SubBean(int a){
superAngel;
}

4.Re:java的构造方法 [Re: dawnlong2000] Copy to clipboard
Posted by: dawnlong2000
Posted on: 2005-01-20 17:11

Sorry,i'm mistaken.
in class SubBean,the following constructor declaration will be OK.
public SubBean(int a){
super( a );
}

5.Re:java的构造方法 [Re: dawnlong2000] Copy to clipboard
Posted by: sfki830329
Posted on: 2005-01-26 19:17

本人认为在父类中加一个空的构架方法就行了。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923