jeudi 25 juin 2015

Do constructors always have to be public? [duplicate]

This question already has an answer here:

My first question is -

   class Explain() {
        public Explain() {
      }
   }

Should Constructor always declared as public?

What if I create a private constructor.

I always seen constructors are implicitly public. So why private constructor is useful? Or is it not useful at all. Because nobody could ever call it, or never make an object ! And that is my second question.

Thanks.

Aucun commentaire:

Enregistrer un commentaire