Last active
September 26, 2018 01:56
-
-
Save gotoark/20497a4672bf08253ae11f7c1dd5b537 to your computer and use it in GitHub Desktop.
Singleton Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package singleton; | |
public class LazyInitialization { | |
//1.private Constructor | |
private LazyInitialization() { | |
} | |
//2.Only Instance of the Class | |
private static LazyInitialization instance = null; | |
//3.Public method to enable global access | |
public static LazyInitialization getClassInstance() { | |
if(inatance!=null) { | |
instance= new LazyInitialization(); //creates instance when its is accessed | |
} | |
return instance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment