In what instances you will declare a constructor to be private

Q

In what instances you will declare a constructor to be private?

✍: Guest

A

When we create a private constructor, we can not create object of the class directly from a client. So you will use private constructors when you do not want instances of the class to be created by any external client. Example UTILITY functions in project will have no instance and be used with out creating instance, as creating instances of the class would be waste of memory.

2007-10-23, 5711👍, 0💬