默认情况下,Java构造函数不公开吗? [英] Aren't Java constructors public by default?
本文介绍了默认情况下,Java构造函数不公开吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个不同的包。对于一个类,我已经定义了一个构造函数,而没有设置访问修饰符。我想在另一个包中实例化这个类的对象,并得到错误'构造函数xxx()不可见
'。
如果我定义访问修改为 public
这是罚款。
没有访问说明符!= public
我认为构造函数是默认公开的。否修饰符是包私有。检查文档
I have two classes in two different packages. For one class I've defined a constructor without setting access modifier for it. I want to instantiate an object of this class in another package and get the error 'the constructor xxx() is not visible
'.
If I define access modified to public
it is fine. I thought constructors are public by default?
解决方案
no access specifier != public
No Modifier is package private. check doc
这篇关于默认情况下,Java构造函数不公开吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文