Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aren't Java constructors public by default? [duplicate]

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?

like image 624
Eugene Avatar asked Jan 12 '11 12:01

Eugene


2 Answers

no access specifier != public

No Modifier is package private. check doc

like image 143
jmj Avatar answered Oct 12 '22 12:10

jmj


No, they're not. They have package-visibility by default.

like image 37
skaffman Avatar answered Oct 12 '22 13:10

skaffman