How to resolve 'Implicit super constructor classA() is not visible. Must explicitly invoke another constructor'?

前端 未结 4 1390
[愿得一人]
[愿得一人] 2020-12-17 17:12

I am having a class \'ClassA\' which is having private constructor.

public final class ClassA{
  private ClassA{
  }

  public static void main(String[] arg)         


        
4条回答
  •  执笔经年
    2020-12-17 17:16

    Change the constructor visibility of ClassA from private to protected.

    Constructors always begin by calling a superclass constructor. If the constructor explicitly contains a call to a superclass constructor, that constructor is used. Otherwise the parameterless constructor is implied. If the no-argument constructor does not exist or is not visible to the subclass, you get a compile-time error.

提交回复
热议问题