class Tip1{
private String title;
private String content;
private int publishtime;
Tip1(){
System.out.println("我输出的是无参的构造方法");
}
Tip1(String title){
System.out.println("我输出的有参构造的构造方法");
this.title = title;
}
}
class topic1 extends Tip1{
private String topicId;
private String boardId;
topic1(){
super("canshu");
System.out.println("我是子类的无参构造方法");
}
topic1(String topicId){
System.out.println("我是子类的有参构造方法");
this.topicId = topicId;
}
}
public class TestSuper {
public static void main(String[] args) {
// TODO Auto-generated method stub
topic1 t1 = new topic1("hello");
topic1 t2 = new topic1();
}
}
***输出结果***
我输出的是无参的构造方法
我是子类的有参构造方法
我输出的有参构造的构造方法
我是子类的无参构造方法
该例子摘抄自以上网址。
个人暂时得出结论:当子类中存在对父类的继承时,若所调用的子类方法中无Super(),则默认继承父类中的无参构造方法。