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 class level lock ?
What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?
Assume a thread has lock on it, calling sleep() method on that thread will release the lock?
What is singleton pattern?
How does indexof work?
What is the difference between the ">>" and " >>>" operators in java?
What is difference between an object and a class?
Why does abstract class have constructor?
How will you compute size of a structure?
define the terminology association.
How to sort list of list in java?
What is the difference between replace and replace all?
How do you insert a line break?
How many unicode characters are there?
How to convert string to char and vice versa?