Can a constructor be private in Java?

  • No, constructors can only be package-private
  • No, constructors must always be public.
  • Yes, constructors can be private in Java.
  • Yes, constructors can only be protected.
Yes, constructors can be private in Java. A private constructor is often used in design patterns like Singleton to ensure that only one instance of a class can be created. It restricts external instantiation of the class.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *