I have two classes :
First, with one constructor :
public class First {
First (ObjectA myObjectA) {
//do stuff
}
}
And Second, with two constructors :
public class Second {
Second (ObjectB myObjectB) {
//do something...
}
Second (ObjectC myObjectC) {
//do something else...
}
}
When I want to instantiate my First
class, Eclipse generates me an error ("The constructor is not visible"), I have to add public
to the constructor of First
:
First first = new First(myObject); //Error : "The constructor is not visble"
But when I instantiate my Second
class, I have no error :
Second second = new Second(myObjectC); //No error...
Notes: I instantiate First
in an other class, but I instantiate Second
in First
. First
and Second
are in the same package.
Can you explain me why ?
First
,Second
and the class(es) where you try to instantiate them? – Abeupublic
,private
,protected
, and "no modifier".public
can be accessed from anywhere,private
only from within the same class,protected
from a subclass, and "no modifier" from any class in the same "package". – Fennel