What is the impact of declaring a constructor private in a class?

  • It restricts the instantiation of the class to only within the class itself.
  • It makes the constructor available to other classes for inheritance.
  • It prevents the class from having any constructors.
  • It allows the constructor to be called by any other class.
When a constructor is declared as private in a class, it restricts the instantiation of the class to only within the class itself. This is often used in singleton design patterns, where only one instance of the class is allowed. Option 1 is the correct impact. The other options do not accurately describe the impact of a private constructor.
Add your answer
Loading...

Leave a comment

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