What is singleton class?
Answer Posted / ranganathkini
A Singleton is a class which at any given time has only one
instance and it does not allow more instances to be created.
Such classes do not have an accessible constructor, for example:
public class Singleton {
// class is automatically instantiated when the
// class is loaded
private static Singleton instance = new Singleton()
// constructor is made inaccessible by declaring
// it private
private Singleton() { ... }
// Access to the single instance of the class is
// provided by a static accessor method
public static Singleton getInstance() {
// returns a reference of the private instance
return instance;
}
// rest of the class implementation
}
| Is This Answer Correct ? | 176 Yes | 21 No |
Post New Answer View All Answers
What is difference between add() and addelement() in vector?
Explain what pure virtual function is?
Name few "optional" classes introduced with java 8 ?
Can array grow dynamically in java?
What is data type in computer?
Can private members of a base class are inheritable justify?
Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?
What is the access scope of protected access specifier?
which is advanced deep technology in java launched by the sun microsystem??? The answer is very logical If u need correct answer mail me at priya_gupta@gmail.com
Why singleton class is used in java?
Can final class have constructor?
What will be the default values of all the elements of an array defined as an instance variable?
Can a boolean be null java?
What do you understand by casting in java language?
What things should be kept in mind while creating your own exceptions in java?