Untitled

Untitled

调用this.A(youcan)之后,往后再考虑调用父类的那些构造器。

package shi31;

public class a {
    a(){
        System.out.println("a 无参");
    }
    a(String x){
        System.out.println("a 有参");
    }

    public static void main(String[] args) {
        c c = new c();
    }
}
class b extends a{
    b(){
        System.out.println("b 无参");
    }
    b(String x){
        System.out.println("b 有参");
    }
}

class c extends b{
    c(){
        this("hahaha");
        System.out.println("c无参");
    }
    c(String x){
        super("haha");
        System.out.println("c有参");
    }
}

a 无参 b 有参 c有参 c无参

注意到,c无参的第一行是this,因此不会直接隐式调用,而是后面才。