fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Manager {
  6. static final List<String> collection;
  7. static {
  8. System.out.println("initialize the Manager...");
  9. collection = new ArrayList<>();
  10. System.out.println("done initialize the Manager...");
  11. }
  12.  
  13. static void addThing(String thing) {
  14. collection.add(thing);
  15. }
  16. }
  17.  
  18. class Something {
  19. static {
  20. System.out.println("Initialize Something");
  21. Manager.addThing("something");
  22. System.out.println("Done Initialize Something");
  23. }
  24.  
  25. static void hello() {
  26. System.out.println("Hello");
  27. }
  28. }
  29.  
  30.  
  31. /* package whatever; // don't place package name! */
  32.  
  33.  
  34. /* Name of the class has to be "Main" only if the class is public. */
  35. class Ideone
  36. {
  37. public static void main (String[] args) throws java.lang.Exception
  38. {
  39. System.out.println("main");
  40. Something.hello();
  41. System.out.println("done main");
  42. }
  43. }
Success #stdin #stdout 0.06s 32404KB
stdin
Standard input is empty
stdout
main
Initialize Something
initialize the Manager...
done initialize the Manager...
Done Initialize Something
Hello
done main