fork download
  1.  
  2. class Demo {
  3. static int x;
  4.  
  5. static {
  6. // This block runs once before main()
  7. x = 10;
  8. System.out.println("Static block executed.");
  9. }
  10. }
  11.  
  12. public class Main {
  13. public static void main(String[] args) {
  14. System.out.println("Main method starts.");
  15. System.out.println("Value of x: " + Demo.x);
  16. }
  17. }
  18.  
Success #stdin #stdout 0.1s 55624KB
stdin
Standard input is empty
stdout
Main method starts.
Static block executed.
Value of x: 10