fork download
  1. class Test {
  2. static int i;
  3. int j;
  4.  
  5. // start of static block
  6. static {
  7. i = 10;
  8. System.out.println("static block called ");
  9. }
  10. // end of static block
  11. }
  12.  
  13. class Main {
  14. public static void main(String args[]) {
  15.  
  16. // Although we don't have an object of Test, static block is
  17. // called because i is being accessed in following statement.
  18. System.out.println(Test.i);
  19. Test t = new Test();
  20. System.out.println(t.i);
  21.  
  22. }
  23. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
static block called 
10
10