Static block initialization

Recently, my friend Chandru came up with a new problem in java.

Try solving the below problem without java.exe 🙂

public class StaticUnderstanding {
	public static void main(String[] args) {
		SubClass.dummyMethod();
	}
}
class SuperClass {
	static {
		System.out.println("In superclass...");
	}
	protected static void dummyMethod(){
		System.out.println("In dummy method...");
	}
}
class SubClass extends SuperClass {
	static {
		System.out.println("In subclass...");
	}
}

If you come with any answer other than the below, then you need to read  JLS 12.4 – Initialization of Classes and Interfaces.

In superclass…

In dummy method…

Thanks to Sai for getting this awesome data !!

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

Advertisements