What is the singleton class in java?

Answer Posted / naman patidar

A singleton class can never have more then one instance.
Example :

class SingletonClass {
private static SingletonClass singleObject;

public static SingletonClass getInstance() {
if (singleObject == null) {
singleObject = new SingletonClass();
}
return singleObject;
}
}

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is hql in java?

485


What is meant by pass by reference and pass by value in java?

511


What is the difference between Logical Parallelism and Physical Parallelism?

2947


What is custom tag in java?

518


What is java bean class?

486






What is a singleton in java?

484


explain isalive() method under thread class?

577


Is java a framework?

475


What is an api in java?

482


What are orm tools in java?

584


explain how java se 8 data and time api solves issues of old java date api?

556


What happens when the parent process of a child process exits before the child ?

537


What are jpa annotations?

471


Which is best framework in java?

491


How can the static main method use instance variables?

521