class TestA {
}
class TestB extends TestA {
super();
}
public class Test {
}
super()和this ()不能共存,否则编译时会报异常。
Constructor call must be the first statement in a constructor
换句话说就是super()和this ()都必须在构造方法的第一行。
this(有参数/无参数) 用于调用本类相应的构造函数
super(有参数/无参数) 用于调用父类相应的构造函数
而且在构造函数中,调用必须写在构造函数定义的第一行,不能在构造函数的后面使用。
一个构造函数定义中不能同时包括this调用和super调用,如果想同时包括的话,可以在this()调用的那个构造函数中首先进行super()调用。也可以把TestB()这个方法修改成非构造方法,在构造方法TestB(int i)中调用。