【发布时间】:2014-05-01 19:44:15
【问题描述】:
我正在尝试以下场景:
public class SuperClass {
public SuperClass(){
System.out.println("Super Constructor");
}
public SuperClass(int i){
this();
System.out.println("Parameterized Super Constructor");
}
}
public class SubClass extends SuperClass{
public SubClass(){
System.out.println("Sub Constructor");
}
public SubClass(int i){
super(i); /* Need to call **this()** here .. Is this possible? */
System.out.println("Parameterized Sub Constructor");
}
}
public class Inheritance {
public static void main(String[] args) {
SubClass sub=new SubClass(5);
}
}
在这种情况下如何调用默认构造函数和参数化构造函数?
【问题讨论】:
标签: java inheritance parameterized default-constructor