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 bigger kb or mb?

583


Who found java?

548


what is mutual exclusion? How can you take care of mutual exclusion using java threads? : Java thread

672


What is field name?

585


What is appletviewer?

564






How do you sort in java?

590


What are the common uses of "this" keyword in java ?

569


Can I declare a class as private?

586


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

563


Why java is considered as platform independent?

588


How to display names of all components in a Container?

2488


When is the arraystoreexception thrown?

566


What is lossy conversion in java?

557


What are the supported platforms by java programming language?

565


How do you check if a string contains only numeric digits?

615