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 bitwise complement?
Can a constructor be protected?
What are the uses of synchronized keyword?
What is the purpose of skeleton and stub?
What do you mean by stack?
Can we override the static methods?
Do you need to import math in java?
Can we override the overloaded method?
What is a website container?
Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.
Can a class be declared as static?
Can we catch more than one exception in single catch block?
What do you understand by looping in java? Explain the different types of loops.
How variables are declared?
Explain how to force the garbage collection in java.