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
What is bigger kb or mb?
Who found java?
what is mutual exclusion? How can you take care of mutual exclusion using java threads? : Java thread
What is field name?
What is appletviewer?
How do you sort in java?
What are the common uses of "this" keyword in java ?
Can I declare a class as private?
How to change the priority of thread or how to set priority of thread?
Why java is considered as platform independent?
How to display names of all components in a Container?
When is the arraystoreexception thrown?
What is lossy conversion in java?
What are the supported platforms by java programming language?
How do you check if a string contains only numeric digits?