2
Reply

What is the use of Private Constructor in a Class?

Daljeet Singh

Daljeet Singh

Sep 25, 2012
1.4k
0

    1.) To initialize the private variables in a class. 2.) Also to ensure or prevent user from creating instance of a class. Similar to singleton pattern in which - class object will be created internally and passed in through a Public static property etc. So developer will not be able to create instance by calling default constructor.

    NitRiX Reloaded
    October 02, 2012
    0

    Its use whe we are using singleton pattern in application development. Its bind to developer to can not create another instance if already one instance exist and its also restrict developer to create default instance of class.

    Sandeep Singh Shekhawat
    September 28, 2012
    0