Two Laptop Bag*
The moose likes Beginning Java and the fly likes private constructers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "private constructers" Watch "private constructers" New topic
Author

private constructers

gopala krishna muvvala
Greenhorn

Joined: Aug 26, 2008
Posts: 3
Is possible to create object for private constructer in java

in this way

class demo
{
private demo(String s)
{
System.out.println(s);
}
public static void main(String[] ar)
{
demo d=new demo("gopal");
}
}
[ August 26, 2008: Message edited by: gopala krishna muvvala ]
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
Yes. Objects can be created in the class itself. Check Singleton pattern for more information
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Welcome to JavaRanch
There was similar discussion last week: here.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: private constructers