about abstract class

yes, we do know abstract class cannot be instantiated, if it's extended, its constructor is not allowed to be private, that's because its derivative wants to use its super constructor which also means it'll be called associated with its derivative instantiation. let's see the following example:

 

abstract class Father {
    protected Father() {
        System.out.println("Father");
    }
}

public class Test extends Father {

    private Test() {
        System.out.println("Test");
    }

    public static void main(String[] args) {
        new Test();
    }
}

 

its output is supposed to be:

Father

Test

 

你可能感兴趣的:(abstract class)