I played with the code a bit and the answer seems to be the thread which loads the class the first time(only) is the thread which executes the static block and method. So in your example above the answer is the main thread.
I used the code below if you want to play with it a bit:
public class SCJA_4 {
static {
System.out.println("BLOCK: " + Thread.currentThread().getName());
func("JAVA");
Thread t = new Thread(new SCJA_4b());
t.setName("New thread.");
t.start();
//new SCJA_4c();
System.exit(1);
}
public static void func(String s){
System.out.println(s + " is a wonderful language...");
System.out.println("FUNC: " + Thread.currentThread().getName());
}
}
class SCJA_4b extends Thread {
static {
System.out.println("BLOCK: " + Thread.currentThread().getName());
func("C++");
}
public static void func(String s){
System.out.println(s + " is a wonderful language...");
System.out.println("FUNC: " + Thread.currentThread().getName());
}
public void run () {
new SCJA_4c();
}
}
class SCJA_4c {
static {
System.out.println("BLOCK: " + Thread.currentThread().getName());
func("PERL");
}
public static void func(String s){
System.out.println(s + " is a wonderful language...");
System.out.println("FUNC: " + Thread.currentThread().getName());
}
}
The output of the above code is:
BLOCK: main
JAVA is a wonderful language...
FUNC: main
BLOCK: main
C++ is a wonderful language...
FUNC: main
BLOCK: New thread.
PERL is a wonderful language...
FUNC: New thread.