Pages

Saturday, April 5, 2014

Singleton in Java

In object-oriented programming , a singleton class is a class that can have only one object (an instance of the class) at a time.Below is the example of singleton class in Java.

For more update about android click below link
public class ClassicSingleton {
private static ClassicSingleton instance = null;
protected ClassicSingleton() {
// Exists only to defeat instantiation.
}
public static ClassicSingleton getInstance() {
if(instance == null) {
instance = new ClassicSingleton();
}
return instance;
}
}
Click below for more update about android