How to create an instance of a class if the class has
private constructor?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / krishnanv
The above answer is perfectly ok only one thing missing i.e
the getObj() method must be static, then only we can call
directly without instantiating that class object.
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / meera
create an instance of a class within the same class.
then u can create an instance of a class if the class has
private constructor.
| Is This Answer Correct ? | 3 Yes | 2 No |
What is field name?
How to sort array in descending order in java?
How are the elements of a gridbaglayout organized?
How do you use compareto?
What is a string what operation can be performed out with the help of a string?
What is the biggest integer?
How many bits is a string?
What are JVM.JRE, J2EE, JNI?
Why is prepared Statement, Callable Statement used for? What is the need of Batch updates?
What is the difference between abstract class and interface1? What is an interface?
How do you stop a thread in java?
What does java ide mean?