Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1.  
  2. public class Main {
  3.  
  4. public static void main(String[] args) {
  5. Singleton s = Singleton.getInstance();
  6. System.out.println(s.text);
  7.  
  8. }
  9.  
  10. }
  11.  
  12. class Singleton{
  13.  
  14. private static Singleton single_instance = null;
  15. public String text;
  16.  
  17. private Singleton() {
  18. text = "Coś do wypisania.";
  19. }
  20.  
  21. //tworzenie instancji klasy Singleton
  22. public static Singleton getInstance()
  23. {
  24. if (single_instance == null)
  25. single_instance = new Singleton();
  26.  
  27. return single_instance;
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement