Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




What is Private Constructor? and it’s use? Can you create instance of a class which has Private Constructor

When a class declares only private instance constructors, it is not possible for classes outside the program to derive from the class or to directly create instances of it. (Except Nested classes)

Make a constructor private if:

- You want it to be available only to the class itself. For example, you might have a special constructor used only in the implementation of your class Clone method.

- You do not want instances of your component to be created. For example, you may have a class containing nothing but Shared utility functions, and no instance data. Creating instances of the class would waste memory.

Share this article   |    Print    |    Article read by 2127 times
Author:
Guest
Guest user is that user who have done some activity on website without login. Activity contains commenting on any article, uploading an image on website etc.
Related Articles: No related article
Related Interview Questions: