如何解决'Implicit super constructor classA()不可见。必须显式调用另一个构造函数? [英] How to resolve 'Implicit super constructor classA() is not visible. Must explicitly invoke another constructor'?

查看:2148
本文介绍了如何解决'Implicit super constructor classA()不可见。必须显式调用另一个构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类'ClassA',它有私人构造函数。

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

public final class ClassA{
  private ClassA{
  }

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



现在,我扩展了类'ClassA' final keyword was removed before doing this]

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) }{
      ;
      ;
      ;
      }

}

c $ c>隐式超级构造函数classA()不可见。必须显式调用另一个构造函数。

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?

注意我无法更改ClassA构造函数的访问说明符。

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

推荐答案

将ClassA的构造函数可见性从 private 更改为 protected

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.

这篇关于如何解决'Implicit super constructor classA()不可见。必须显式调用另一个构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆