子类的构造函数中不是必须使用super,在构造函数中,如果第一行没有写super(),编译器会自动插入.但是如果父类没有不带参数的构造函数,或这个函数被私有化了(用private修饰).此时你必须加入对父类的实例化构造.而this就没有这个要求,因为它本身就进行实例化的构造.
如果父类的构造函数是无参的,那子类构造函数会在第一行默认调用super().
下面这种情况是必须调用super()的:
1 public class Father { 2 public String name; 3 public Father(String name) { 4 this.name = name; 5 } 6 } 7 8 class Son extends Father{ 9 public Son(String name) { 10 super(name); 11 } 12 //必须调用,否则他会默认调用父类的无参构造函数,而父类的无参构造函数已经被有参的覆盖,所以找不到