Sunday, January 17, 2010

Java Static Block Questions

class child extends Parent {

    public static void fun() {
        System.out.println("Inside fun");
    }
    static {
        System.out.println("Child static block " + (i + 1));
    }

    public static void main(String[] args) {

    }
}

class Parent {
    static int i = 3;
    static {
        System.out.println("Parent static block");
    }
}


Output
Parent static block
Child static block 4

No comments: