<<< Attributes | Index | Constructors revisited >>> |
Static attributes are shared by all objects instantiated for a given class.
This means that only a single copy of static attribute is allocated in memory.
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; } }
<<< Attributes | Index | Constructors revisited >>> |