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...

How to create an instance of a class if the class has
private constructor?

Answer Posted / eswar

u can create instance like this...

class Ex
{
public static Ex e=null;

private Ex()
{}

public Ex getObj()
{
if(e==null)
e=new Ex();
return e;
}
}

Actually the above coding is example for singleton Java
class.... which creates omly one object per JVM

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is class level lock ?

971


What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?

1000


Assume a thread has lock on it, calling sleep() method on that thread will release the lock?

1044


What is singleton pattern?

1039


How does indexof work?

893


What is the difference between the ">>" and " >>>" operators in java?

927


What is difference between an object and a class?

1070


Why does abstract class have constructor?

944


How will you compute size of a structure?

1073


define the terminology association.

1048


How to sort list of list in java?

1031


What is the difference between replace and replace all?

944


How do you insert a line break?

855


How many unicode characters are there?

981


How to convert string to char and vice versa?

956