Java initializer block syntax

Damien Cassou damien.cassou at gmail.com
Tue Oct 9 15:27:56 UTC 2007


The following code results in:

"
In the main()
In staticMethod
In the Main initializer block
In the Main constructor
In the B initializer block
In the B constructor
"

public class Main {

	String var = staticMethod();
	
	public static String staticMethod() {
		System.out.println("In staticMethod");
		return "";
	}
	
	{
		System.out.println("In the Main initializer block");
	}
	
	public Main() {
		System.out.println("In the Main constructor");
	}
	
	public static void main(String[] args) {
		B b;
		
		System.out.println("In the main()");
		b = new B();
	}
}

public class B extends Main{
	public B() {
		super();
		System.out.println("In the B constructor");
	}
	{
		System.out.println("In the B initializer block");
	}
	
	
}

-- 
Damien Cassou



More information about the Squeak-dev mailing list