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?

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / krishnanv

The above answer is perfectly ok only one thing missing i.e
the getObj() method must be static, then only we can call
directly without instantiating that class object.

Is This Answer Correct ?    2 Yes 0 No

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

Answer / meera

create an instance of a class within the same class.
then u can create an instance of a class if the class has
private constructor.

Is This Answer Correct ?    3 Yes 2 No

Post New Answer

More Core Java Interview Questions

Can one thread block the other thread?

0 Answers  


What is encapsulation in java?

0 Answers   IBS, NIIT,


What do you mean by object?

0 Answers  


What is the use of bin and lib in JDK?

8 Answers   TCS,


What is the full form of jpeg?

0 Answers  


What does @override mean?

0 Answers  


Why only one Class is public in one file? Explain in details. Thanks in Advance.

12 Answers  


Does java support multiple inheritance or not?

0 Answers   Hexaware,


Can we instantiate Interfaces?

7 Answers   Ericsson,


which class to use when concatenating strings in a loop.

3 Answers   IBM,


How to change the priority of thread or how to set the priority of thread?

0 Answers  


Difference between array and arraylist.

23 Answers   Arise Solution, Banca Sella, iFocus, NIC, Sai Softech, Solartis, TCS, Verizon,


Categories