-4

Why does the following code print "Bo-Bo Go-Go", instead of "Bo-Bo Hello, World! Go-Go?

public class Test {
    static {
        System.out.print("Bo-Bo ");
    }

    public static void main(String[] args) {
       System.out.print("Hello, World! ");
    }
    static {
        System.out.println("Go-Go ");
        System.exit(0);
    }
} 
Joey Harwood
  • 961
  • 1
  • 17
  • 27

1 Answers1

3

Because static initialization blocks run before the entry-point (both of them), and the second one exits thus main is never entered.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249