Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
723 views
in Technique[技术] by (71.8m points)

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

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

public final class ClassA{
  private ClassA{
  }

  public static void main(String[] arg) }{
  ;
  ;
  ;
  }
}

Now, i am extending the class 'ClassA' [ final keyword is removed before doing this ]

public class ClassB extends ClassA{
     public static void main(String[] arg) }{
      ;
      ;
      ;
      }

}

Now, i am getting Implicit super constructor classA() is not visible. Must explicitly invoke another constructor. What does it mean and how to resolve this?

Note i can not change the access specifier of ClassA constructor.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...