I have the following simple hello world in Java:
class A {
static {
System.out.println(\"Hello world\");
}
}
It works as ex
When classes are loaded to the JVM, it first "process" what is in the static block, which is why it prints out "Hello World" first, which explains this part:
class A {
static {
System.out.println("Hello world");
}
}
When you run the program it looks for the "main" method, hence it prints out the Hello World first then looks for the main method, hence the error, same logic is applied when you call the method inside the static block.