How to prevent to create multiple objects of a java class?
Answers were Sorted based on User's Feedback
Answer / sadiq
Using Singleton Design pattern we can prevent class creating
multiple objects.
| Is This Answer Correct ? | 30 Yes | 3 No |
Answer / naseer
declare constructor as private .that class only create one object
| Is This Answer Correct ? | 10 Yes | 6 No |
How will you load a specific locale?
Why there are some null interface in java? What does it mean?
public class Garbage { int a=0; public void add() { int c=10+20; System.out.println(c); System.out.println(a); } public static void main(String args[]) { Garbage obj=new Garbage(); System.gc(); System.out.println("Garbage Collected"); obj.add(); } } Above is a code in java used for garbage collection. object obj has been created for the class Garbage and system.gc method is called. Then using that object add method is called.System.gc method if called the obj should be garbage collected?
In the below example, what will be the output?
Why inputstreamreader is used in java?
What is sorting in java?
What are the benefits of operations?
What is instance example?
How to perform merge sort in java?
How do you check if a number is a perfect square?
What are the parameters used in Connection pooling?
What is meant by 'bit masking' in java?