Explain private constructor in java java interview question interviewdot

Publié le: 20 septembre 2013
sur la chaîne: Interview DOT
2,884
8

Click here -    / @interviewdot   to get notifications. Explain private constructor in java java interview question interviewdot
www.InterviewDot.com - Job Portal -- Java Interview Questions

Explain private Constructor in Java ?

Constructors can use any access modifier, including private.

A private constructor means only code within the class itself can instantiate an object
of that type, so if the private constructor class wants to allow an instance of the class to be used, the class must provide a static method or variable that allows access to an instance created from within the class.
Public Class PrivateConstDemo {

private PrivateConstDemo (){ // no other class can instantiate.
}

Public synchronized static PrivateConstDemo getInstance(){
if(demo == null){
demo = new PrivateConstDemo();
}
}
}
A Job Portal
http://www.InterviewDot.com http://www.InterviewDot.com http://www.InterviewDot.com
One Click Dream Job - http://www.interviewdot.com/upload-re...

Other Top Job Portals
www.Naukri.com
www.MonsterIndia.com
www.TimesJobs.com

Are you looking for a new Job ?
InterviewDot.com - A Job Portal
http://www.InterviewDot.com http://www.InterviewDot.com http://www.InterviewDot.com
One Click Dream Job - http://www.interviewdot.com/upload-re...


Sur cette page du site, vous pouvez voir la vidéo en ligne Explain private constructor in java java interview question interviewdot durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Interview DOT 20 septembre 2013, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 2,884 fois et il a aimé 8 téléspectateurs. Bon visionnage!