• What I am doing ?

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

  • June 2011
    M T W T F S S
    « Oct   Sep »
  • Archives

  • Viewers

  • Advertisements

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) {
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