Search code examples
javainheritanceconstructorprivate

Why does a private base class constructor result in "Implicit super constructor is not visible"


If constructors do not inherits in Java, why do I get compile error(Implicit super constructor A() is not visible for default constructor. Must define an explicit constructor)?

class A {
    private A() {
    }
}

public class B extends A {

}

UPD. I know that super() is called in implicit B constructor. But i don't get why it can't access private constructor with super(). So, if we have only private constructors, class de facto is final?


Solution

  • if B extends A, B must have an access to an A constructor.

    Keep in mind that a constructor always call super(). So here, the implicit parameterless constructor of B can't call the A constructor.