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
Why are arrays useful in java?
What are methods of a class?
How can we create a synchronized collection from given collection?
How do you check if an arraylist is not empty?
Can we increase size of array?
How do you change an int to a string?
How do you create immutable object in java?
What is better- service oriented or batch oriented solutions?
what are different ways in which a thread can enter the waiting state? : Java thread
What is bubble sorting in java?
Can an interface have a class?
What is array and arraylist in java?
Define max and min heap, also the search time of heap.
How to display arraylist values in java?
What is string in java?