This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes constructor with private access modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "constructor with private access modifier" Watch "constructor with private access modifier" New topic
Author

constructor with private access modifier

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
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.

I didnot uderstand this point :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.

Please make me understand this point
Thanks in advance


Abhishek
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

It's just a plain and clear English sentence, but your native language probably isn't English. I'll try to explain it with code.

An example of where this technique is useful is in the implementation in Java of the singleton design pattern.
[ August 17, 2006: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constructor with private access modifier
 
Similar Threads
Constructor Rules
private constructor
Invoking Private Constructor
constructors
Is it possible for a class to have a private constuctor???