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

Why are arrays useful in java?

1018


What are methods of a class?

1024


How can we create a synchronized collection from given collection?

1078


How do you check if an arraylist is not empty?

1113


Can we increase size of array?

1022


How do you change an int to a string?

995


How do you create immutable object in java?

1036


What is better- service oriented or batch oriented solutions?

2205


what are different ways in which a thread can enter the waiting state? : Java thread

961


What is bubble sorting in java?

1035


Can an interface have a class?

1000


What is array and arraylist in java?

1101


Define max and min heap, also the search time of heap.

1020


How to display arraylist values in java?

999


What is string in java?

1004