public class Test {
public static void main(String [] args){
Child c = new Child();
}
}
class Father{
public Father(){
System.out.println("父类无参构造函数");
}
public Father(String name){
System.out.println("父类有参构造函数");
}
}
class Child extends Father{
public Child(){
this("dd");
System.out.println("子类无参构造函数");
}
public Child(String name){
System.out.println("子类有参构造函数");
}
}
- A . 子类无参构造函数 子类有参构造函数
- B . 子类有参构造函数 子类无参构造函数
- C . 父类无参构造函数 子类有参构造函数 子类无参构造函数
- D . 父类有参构造函数 子类有参构造函数 子类无参构造函数
答案为:C 父类无参构造函数 子类有参构造函数 子类无参构造函数
解释:当调用this()时,会默认调用super()函数,因为this()中无参数,只能调用父类的无参构造函数
解释:当调用this()时,会默认调用super()函数,因为this()中无参数,只能调用父类的无参构造函数