fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. protected static String str;
  12. private static int runningLoop;
  13.  
  14. static{
  15. str = "Static Block";
  16. }
  17.  
  18. /**
  19. * Non-Static Method Accessing Static Member
  20. */
  21. public void modifyStaticMember(){
  22. str = "Non-Static Method";
  23. }
  24.  
  25. /**
  26. * Non-Static Method invoking Static Method
  27. */
  28. public void invokeStaticMethod(){
  29. String[] args = {};
  30. if(runningLoop == 0){
  31. runningLoop++;
  32. main(args);
  33. }
  34. //Exiting as it will lead to java.lang.StackOverflowError
  35. System.exit(0);
  36. }
  37.  
  38. public static void main (String[] args)
  39. {
  40. Ideone instance = new Ideone();
  41. System.out.println(str);
  42. instance.modifyStaticMember();
  43.  
  44. // Changed Value persists
  45. System.out.println(str);
  46.  
  47. //Invoking Static Method
  48. instance.invokeStaticMethod();
  49. }
  50. }
Success #stdin #stdout 0.09s 321600KB
stdin
Standard input is empty
stdout
Static Block
Non-Static Method
Non-Static Method
Non-Static Method