How to implement or use the singleton class in java?
Answer Posted / amit sharma
singleton is a design pattern. in this per application only
one object should exist.we implement it as follows:
public class abcd
{
private static abcd instance=null;
protected abcd()
{
//only to defeat instantiation;
}
public static abcd getInstance()
{
if(instance==null)
{
instance=new abcd();
}
return instance;
}
| Is This Answer Correct ? | 11 Yes | 4 No |
Post New Answer View All Answers
What is java collection? : java collections
What is an algorithm in java collection framework? : java collections
What is the difference between comparable and comparator in java.util pkg?
What are maps interfaces in the java collections? : java collections
What is the use of the list interface in the java collection? : java collections
What are the types of interface used in the java collections? : java collections
What is deque in the java collections framework? : java collections
can u draw class/object diagram for ATM
What are the different types of classes implemented in the set interfaces? : java collections
What are the differences between the java collection and the java list? : java collections
What are the types of the main implementing classes in the map interfaces? : java collections
Hi Friends, i have searched in google but not clear. can you give bank example with synchronized keyword
Should we create system software ( e.g operating system ) in java ?
Explain the OOPS concept in Realtime Scenarion ? Take example as CAR. Please explain indetail ?
What are the main classes of the list interfaces? : java collections