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 bitwise complement?

936


Can a constructor be protected?

1038


What are the uses of synchronized keyword?

959


What is the purpose of skeleton and stub?

1157


What do you mean by stack?

1099


Can we override the static methods?

989


Do you need to import math in java?

945


Can we override the overloaded method?

1065


What is a website container?

905


Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.

1005


Can a class be declared as static?

1120


Can we catch more than one exception in single catch block?

1002


What do you understand by looping in java? Explain the different types of loops.

1003


How variables are declared?

928


Explain how to force the garbage collection in java.

928