Aren't Java constructors public by default?

Eugene picture Eugene · Jan 12, 2011 · Viewed 31.3k times · Source

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?

Answer

Jigar Joshi picture Jigar Joshi · Jan 12, 2011

no access specifier != public

No Modifier is package private. check doc