What is singleton class?
Answer Posted / srinivas pentakota
A singleton is an class that can be instantiated once, and
only once. This is a fairly unique property, but useful in a
wide range of object designs. Creating an implementation of
the singleton pattern is fairly straightforward - simple
block off access to all constructors, provide a static
method for getting an instance of the singleton, and prevent
cloning.
public class SingletonObject
{
private SingletonObject()
{
// no code req'd
}
public static SingletonObject getSingletonObject()
{
if (ref == null)
// it's ok, we can call this constructor
ref = new SingletonObject();
return ref;
}
private static SingletonObject ref;
}
Is This Answer Correct ? | 27 Yes | 14 No |
Post New Answer View All Answers
What is functional interface in java?
Is it possible to compare various strings with the help of == operator?
For ease of programming you can consider the maze as a 2D array with colors represented by below integer and characters (in capital letters). • B - Black • W -White • G- Green • R- Red R B W B W W W W W W B W B B W W W W W W W B W B W W W B W W W W B B W W W B W W W B W W B B B B W B W B W W B W W W B W W W B B B W W B W W W B W W B W B W W W B W B W W W W B B W W W W B W W W W W G Shortest Route Problem: • Solution that finds the shortest Route between Red and Green White will have 1 Weight. Red and Green carry no weights. Shortest path is the path with less weight when you add up the weights in the path.
What is the difference between preemptive scheduling and time slicing?
what is the difference between preemptive scheduling and time slicing? : Java thread
What are the advantages of user defined functions?
Why are getters and setters used?
Explain reverse a linked list recursive java solution?
What is the use of a copy constructor?
Can a constructor have different name than a class name in java?
What is the purpose of file class?
What is parameter example?
What is the purpose of javac exe?
How to sort an array in java without using sort method?
What is passed by reference and pass by value ?