Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

when we create singleton design then we create private
constructtor..so how JVM take private constructor to make
object..but it's private..

Answer Posted / pals

-Singleton design implies only 1 instance of a class can exist
-Private constructor implies only that class's member variables can call the constructor(Create an object)
-So a singleton class will have a private constructor only when you want to create ONLY 1 instance of the class without giving any other class the opportunity to create the class's objs using "new"; so you will have to write a static method in which u create an instance of this class and using this static method expose the reference of this object to the calling classes.So this will make sure that every user will use the same instance of the class.
Summary: JVM lets ONLY the private constructor class's members create only 1 obj of this class and lets other uses use this obj only by exposing a public static method.
I hope this is clear :)

Is This Answer Correct ?    21 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the base class of all exception classes in java?

1056


What is a protected void?

929


What are the super most classes for all the streams?

2561


What is a top level class in java?

1029


What are benefits of java?

1050


Is there any limitation of using inheritance?

1089


Can we have any code between try and finally blocks?

1021


Define "Access specifiers" in java.

1170


What is the difference between hashmap and hashtable? What is an interface?

1165


Give a practical example of singleton class usage?

1058


What is a numeric literal?

1083


Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?

994


What is the use of put method?

954


What is difference between filereader and bufferedreader?

959


Explain importance of finally block in java?

1040