Skip to content

Instantly share code, notes, and snippets.

@IamLizu
Last active September 29, 2019 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IamLizu/30713623061669f8483139f3e52790bf to your computer and use it in GitHub Desktop.
Save IamLizu/30713623061669f8483139f3e52790bf to your computer and use it in GitHub Desktop.
public class main {
public static void main(String[] args) {
System.out.println("Demonstrates Singleton class. Output of the two print statement bellow will be same,");
System.out.println("because the class returned the cached instance of the second call.");
// Initializing one instance of the singleton class
Singleton one = Singleton.getInstance("One");
// Inilializing another instance of singleton class
Singleton two = Singleton.getInstance("Two");
System.out.println(one.text);
System.out.println(two.text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment