Java – how to resolve the invisible ‘implicit super constructor classa() Must explicitly call another constructor?
I have a class "classA", which has a private constructor
public final class ClassA{ private ClassA{ } public static void main(String[] arg) }{ ; ; ; } }
Now, I'm extending the class "classA" [delete the final keyword before doing this]
public class ClassB extends ClassA{ public static void main(String[] arg) }{ ; ; ; } }
Now I get the implicit super constructor classA () invisible You must explicitly call another constructor What does this mean and how to solve this problem?
Note that I cannot change the access specifier of the classA constructor
Solution
Change the constructor visibility of classA from private to protected
Constructors always start by calling a superclass constructor If the constructor explicitly contains a call to the superclass constructor, the constructor is used Otherwise, the parameterless constructor is implicit If the parameterless constructor does not exist or is not visible to subclasses, you will get a compile - time error